Xcode 在 UITableRowSelect 之后显示 UIAlertView



这是我的第一个问题,如果出现问题,对不起

好吧,我正在尝试创建一个视图,我可以在其中从表格视图中选择一个朋友,然后它应该在UIAlertView上显示数字和邮件,但我不知道该怎么做好友列表是从"我的网站"上的 XML 文件中获取的,然后使用自定义单元格设计在表上进行分析

这是创建每个单元格的代码

- (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;
}

谢谢圣地亚哥

您必须实现 didSelectRowAtIndexPath: 方法。

- (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];
}

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath是您需要实现的方法。这是假定您在其中呈现表视图的视图是表视图的委托。

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