Xcode show UIAlertView after UITableRowSelection?

旧时模样 提交于 2019-12-12 04:36:11

问题


this is my first question, sorry if something is wrong

Well I'm trying to create a view in which i can select a friend from a table view and then it should say the number and the mail on a UIAlertView but I dont know how to do this the friend list is obtained from an xml file on my site, and then is parsed an showed on a table with a custom cell design

this is the code that creates each cell

- (UITableViewCell *)tableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = (UITableViewCell *)[self.messageList dequeueReusableCellWithIdentifier:@"ContactListItem"];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ContactListItem" owner:self options:nil];
        cell = (UITableViewCell *)[nib objectAtIndex:0];
    }

    NSDictionary *itemAtIndex = (NSDictionary *)[messages objectAtIndex:indexPath.row];
    UILabel *userLabel = (UILabel *)[cell viewWithTag:2];
    userLabel.text = [itemAtIndex objectForKey:@"user"];

    return cell;
}

thanks Santiago


回答1:


You have to implement the didSelectRowAtIndexPath: method.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  NSDictionary *itemAtIndex = (NSDictionary *)[messages objectAtIndex:indexPath.row];
  NSString *name = [itemAtIndex objectForKey:@"user"];
  NSString *email = [itemAtIndex objectForKey:@"email"];
  NSString *phone = [itemAtIndex objectForKey:@"phone"];
  NSString *messageStr = [NSString stringWithFormat:@"Email : %@\nPhone : %@", email, phone];

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:name message:messageStr delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
  [alert show];   
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
}



回答2:


-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath is the method you would need to implement. This is assuming the view you are presenting the table view in is the delegate for the table view.

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     //Alert view logic happens here getting all the cell information
}


来源:https://stackoverflow.com/questions/12827536/xcode-show-uialertview-after-uitablerowselection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!