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 に答える