내 테이블보기에있는 사용자 정의 UITableCell 내에서 UITextField에서 textFieldShouldReturn을 호출하려고합니다. 나는 셀의 인덱스 경로를 잡기 위해 코드의이 비트를 사용, 나는 또 다른 게시물에 유래에이 방법을 발견사용자 정의 UITableCell 내의 UITextField에서 textFieldShouldReturn을 호출하는 데 문제가 있습니다.
NSIndexPath *indexPath = [self.tableView indexPathForCell:(friendTableCell*)[[textField superview] superview]];
나는 오류를 가지고, 내가 컴파일 할 때와 실행하지 않는,하지만 내가 선택하는 경우 셀을 입력하고 텍스트를 입력 한 다음 키보드에서 반품을 시도하면 아무 일도 일어나지 않습니다. 오히려 길기 때문에 호출해야하는 코드의 나머지 부분은 제외했습니다. 그리고 didSelectRowAtIndexPath에서 테스트했으며 작동합니다. 누군가가 정말로 보살펴 주면 그것을 포함시킬 수 있습니다. 아마도 내 대리자가 키보드에 제대로 설정되지 않았지만 내 머리글에 UITextFieldDelegate가 포함되어 있다고 생각하고 실제로 사용자 지정 셀에 액세스 할 때 키보드의 대리자를 설정하는 방법을 잘 모르겠습니다. 테이블 뷰. 누군가가해야 할 일에 대한 아이디어 나 다른 방법을 가지고 있다면 정말 감사 할 것입니다. 감사!
UPDATE - 컨테이너 뷰와 셀 사이에 다른 층이있는 ScrollView가 완전 textFieldShouldReturn 방법
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:(friendTableCell*)[[[textField superview] superview] superview]];
NSString *sectionTitle = [self.usernameSectionTitles objectAtIndex:indexPath.section];
NSArray *sectionUser = [self.sortedUsernames objectForKey:sectionTitle];
self.recipient = [sectionUser objectAtIndex:indexPath.row];
friendTableCell *cell = (friendTableCell *)[self.tableView cellForRowAtIndexPath:indexPath];
NSString *sendingUser = self.currentUser.username;
NSString *message = [NSString stringWithFormat:@"from %@", [sendingUser uppercaseString]];
if ([self.locationSwitch isOn])
{
if ([cell.message.text length] > 0)
{
message = [NSString stringWithFormat:@"from %@ %@", [sendingUser uppercaseString],cell.message.text];
}
CLLocation *location = locationManager.location;
if(!location)
{
[cell closeMessage:self];
}
dispatch_queue_t queue = dispatch_queue_create("myQueue", DISPATCH_QUEUE_SERIAL);
dispatch_sync(queue, ^{
CLLocationCoordinate2D coordinate = [location coordinate];
PFGeoPoint *geoPoint = [PFGeoPoint geoPointWithLatitude:coordinate.latitude longitude:coordinate.longitude];
PFObject *object = [PFObject objectWithClassName:@"Location"];
[object setObject:geoPoint forKey:@"location"];
[object setObject:self.recipient.objectId forKey:@"recipient"];
[object saveEventually:^(BOOL succeeded, NSError *error) {
if(succeeded){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Your Location was sent!"message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
dispatch_sync(queue, ^{
PFQuery *locationQuery = [PFQuery queryWithClassName:@"Location"];
[locationQuery whereKey:@"recipient" equalTo:self.recipient.objectId];
/****** CHANGE THE getFirstObjectInBackground method so it doesn't take the first each time
or DELETE THE LOCATION after it has been viewed **************/
[locationQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (error) {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
else {
self.locationId = object.objectId;
NSLog(@"Here is you location ID: %@", self.locationId);
dispatch_sync(queue, ^{
self.data = @{
@"alert":message,
@"locationId":self.locationId
};
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"objectId" equalTo:self.recipient.objectId];
PFQuery *query = [PFInstallation query];
[query whereKey:@"currentUser" matchesQuery:userQuery];
PFPush *push= [[PFPush alloc]init];
[push setQuery:query];
[push setData:self.data];
[push sendPushInBackground];
});
}
}];
});
}
}];
});
}
else if ([cell.message.text length] > 0)
{
message = [NSString stringWithFormat:@"from %@ %@", [sendingUser uppercaseString],cell.message.text];
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"objectId" equalTo:self.recipient.objectId];
PFQuery *query = [PFInstallation query];
[query whereKey:@"currentUser" matchesQuery:userQuery];
PFPush *push= [[PFPush alloc]init];
[push setQuery:query];
[push setMessage:message];
[push sendPushInBackground];
}
else
{
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"objectId" equalTo:self.recipient.objectId];
PFQuery *query = [PFInstallation query];
[query whereKey:@"currentUser" matchesQuery:userQuery];
PFPush *push= [[PFPush alloc]init];
[push setQuery:query];
[push setMessage:message];
[push sendPushInBackground];
}
NSLog(@"Message sent!");
[cell closeMessage:self];
[cell resignFirstResponder];
return YES;
}는
당신이 당신의 텍스트 필드에 대한 대리자를 결합했다 .. 당신은 당신이이 일을 할
[textField resignResponder]
희망을 사용해야 대신[cell resignFirstResponder];
를 작성했습니다 볼 수 있습니까? 'textField.delegate = self'? – Vidhi네, 텍스트 필드는 위젯이 custom uitablecell nib 파일에 설정되어 있습니다. – user3353890
CustomCell 또는 tableView 클래스에서 textFieldShouldReturn에 액세스하려는 위치는 어디입니까? –