메시지를 수신하는 ChatViewController.m
은 tableView
에 표시됩니다. 이제 메시지를 보낸 사람이 변경되면 사용자에게 새 메시지 (alert view
)로 전환 할 수있는 옵션을 제공하려고합니다. 사용자가 스위치를 클릭하면 메시지를 표시하는 방법은 무엇입니까?새 데이터로 UIViewController를 새로 고치는 방법은 무엇입니까?
메시지 수신 및 표시 방법입니다.
-(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?
}
}
사용 [의 tableview reloadData]'. 데이터 소스를 업데이트 한 후 –
새 사용자의 경우 새 사용자의 메시지 만 표시하려면 경고 스위치 코드에서 bubbleData의 모든 개체를 제거하고 모든 사용자의 데이터를 bubbleData에 넣으려면 새 사용자의 메시지 만 추가하십시오. 메시지를 표시 한 다음 key "sender"의 bubbleData에 술어를 적용하고 필터링 된 배열을 사용하여 tableview에 데이터를 표시하려면 tableview에 대해 reloadData를 호출하는 것을 잊지 마십시오. –
몇 가지 샘플 코드를 제공해 주시겠습니까? – icodes