When I search through a UITable (not a UITableView) I don't get the same action performed as when I tap on a row without searching.
What I mean is that I have an 'IF' loop:
if (public == NO) {
if ([self.usersTable indexPathForSelectedRow]){
toUser=[users objectAtIndex:[self.usersTable indexPathForSelectedRow].row];
}
This loop is supposed to run when a user taps on a row. This loop runs fine when I don't search the table and manually navigate through.
But when I do search, I get my preconfigured alert telling me that the variable, "toUser" that was supposed to be set is empty.
I check if it's empty by doing this:
else{
[hud hide:YES];
UIAlertView *error = [[UIAlertView alloc]
initWithTitle: @"Select a User"
message: @"Please select a user from the list by either searching for a username or navigating through the list manually."
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[error show];
return;
}
I'm not sure why this is but I expected this logic to work when I search as well.
Here's the code I use to search the table:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//sets cell identifier to the same one in the storyboard.
static NSString *CellIdentifier = @"userCell";
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//NSLog(@"%@", cell);
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
PFObject *tempObject = [self.searchResult objectAtIndex:indexPath.row];
cell.text= [tempObject objectForKey:@"username"];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"users:%lu",[self.searchResult count]);
return [self.searchResult count];
}
I appreciate any help resolving this issue. And examples are very helpful as I'm a beginner at Objective-C.
Thanks so much for your help,
Arman
Aucun commentaire:
Enregistrer un commentaire