ios - 如何使用新数据刷新我的 UIViewController?

标签 ios objective-c uitableview nsdictionary uialertview

这是一个 ChatViewController.m,它接收消息,然后将其显示在 tableView 中。 现在,当消息发送者发生变化时,我想为用户提供切换到新消息的选项(警报 View )。如果用户点击 switch ,如何显示消息?

这就是消息的接收和显示方式。

 -(void)recvdMsg:(NSDictionary *)msg
{
  NSString *currentUser = [msg objectForKey:@"sender"];
  NSString *match = @"@";
  NSString *preAt ;
  NSScanner *scanner = [NSScanner scannerWithString:currentUser];
  [scanner scanUpToString:match intoString:&preAt];

  if (self.name == preAt)  //same sender 
  {
    NSMutableDictionary *newMsg=[[NSMutableDictionary alloc]init];
    NSString *m = [msg objectForKey:@"msg"];
   [newMsg setObject:m forKey:@"message"];
   [newMsg setObject:converID forKey:@"conversationID"];
   [newMsg setObject:@"1" forKey:@"FromTo"];
   NSDate *today=[NSDate date];

   // Convert string to date object
   NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
   [dateFormat setDateFormat:@"MM-dd-yyyy HH:mm:ss"];
   NSString *dt=[dateFormat stringFromDate:today];
   [newMsg setObject:dt forKey:@"timeStamp"];
   [self AddMessage:newMsg]; // adding to database.
   NSBubbleData *heyBubble = [NSBubbleData dataWithText:m date:[NSDate date] type:BubbleTypeSomeoneElse];
   [bubbleData addObject:heyBubble];
   [bbltblView reloadData];
   [bbltblView scrollBubbleViewToBottomAnimated:YES];
}
else     //message from new sender
{   
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"New Message from " message:preAt delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Switch", nil];
}

}

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)  // cancel button clicked
{
    return;
}
else {

    // switch button is clicked....How to go from here.....how would i reload data?
}
}

最佳答案

你可以如下实现alertview delegate metnod

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) //OK Button
    {
       //ok button code
    }
    else //Switch Button
    {
        //switch button code
        [tableview reloadData];
    }
}

关于ios - 如何使用新数据刷新我的 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20512062/

相关文章:

ios - 如何在 mac OS 应用程序中使用 canOpenURL?

ios - 如何设置和获取指针 Swift 的值

ios - UITableViewCell 在点击时编辑单元格内容

ios - 如何将新的 UICollectionViewController 推送到单元格单元格内的导航 Controller

iOS位置后台模式运行时间

ios - 如何每天重复一个 UNUserNotification?

ios - 无法获取第一个单元格的正确索引

objective-c - cocoa , objective-c NIB 加载两次

uitableview - 使用 iOS 6 UITableView dequeueReusableCellWithIdentifier 时设置 UITableViewCell 的样式 :forIndexPath:

swift - Firebase Swift 3 从组中获取多个值