0

这是我的第一个问题,如果有问题请见谅

好吧,我正在尝试创建一个视图,在该视图中我可以从表格视图中选择一个朋友,然后它应该在 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;
}

谢谢圣地亚哥

4

2 回答 2

1

您必须实现该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];
}
于 2012-10-10T20:19:44.677 回答
0

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

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     //Alert view logic happens here getting all the cell information
}
于 2012-10-10T20:15:53.247 回答