这是一个 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/