我正在开发一个聊天应用程序。我的一些类是单例,因此我使用了很多静态方法。更新UI表从静态方法查看
在应用程序委托中收到新消息时。它应该将它发送到我的incomingChat viewController。
我能够在viewcontroller中将新消息传递给静态方法。但我不能从静态方法重新加载表。
InCommingVC.h
#import <UIKit/UIKit.h>
@interface InCommingVC : UIViewController
@property (weak, nonatomic) IBOutlet UINavigationBar *navigationBarTitle;
@property (weak, nonatomic) IBOutlet UITableView *incommingTable;
+ (void) sendIncommingChats:(NSDictionary *) chatDetails;
+ (void) recieveIncomingChat:(NSDictionary *) chatDetails;
@end
InCommingVC.m
#import "InCommingVC.h"
#import "AppDelegate.h"
#import "IncommingItemObject.h"
static NSMutableArray *incomminglist;
@interface InCommingVC(){
AppDelegate *delegate;
}
@end
@implementation InCommingVC
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationBarTitle.topItem.title = @"Incomming Chats";
}
+ (void) recieveIncomingChat:(NSDictionary *) chatDetails{
NSLog(@"GOT A NEW recieveIncomingChat");
NSString *CompanyId = [chatDetails objectForKey:@"CompanyId"];
NSString *ConnectionId = [chatDetails objectForKey:@"ConnectionId"];
NSString *CountryCode = [chatDetails objectForKey:@"CountryCode"];
NSString *Department = [chatDetails objectForKey:@"Department"];
NSString *Name = [chatDetails objectForKey:@"Name"];
NSString *StartTime = [chatDetails objectForKey:@"StartTime"];
NSString *TimeZone = [chatDetails objectForKey:@"TimeZone"];
NSString *VisitorID = [chatDetails objectForKey:@"VisitorID"];
NSString *WidgetId = [chatDetails objectForKey:@"WidgetId"];
NSLog(@"------------------------------------------------------------------------------");
NSLog(@"CompanyId : %@" , CompanyId);
NSLog(@"ConnectionId : %@" , ConnectionId);
NSLog(@"CountryCode : %@" , CountryCode);
NSLog(@"Department : %@" , Department);
NSLog(@"Name : %@" , Name);
NSLog(@"StartTime : %@" , StartTime);
NSLog(@"TimeZone : %@" , TimeZone);
NSLog(@"VisitorID : %@" , VisitorID);
NSLog(@"WidgetId : %@" , WidgetId);
NSLog(@"------------------------------------------------------------------------------");
IncommingItemObject *item = [[IncommingItemObject alloc] init];
[item setCompanyId:CompanyId];
[item setConnectionId:ConnectionId];
[item setCountryCode:CountryCode];
[item setDepartment:Department];
[item setName:Name];
[item setStartTime:StartTime];
[item setTimeZone:TimeZone];
[item setVisitorID:VisitorID];
[item setWidgetId:WidgetId];
if (incomminglist.count == 0) {
incomminglist = [[NSMutableArray alloc] init];
[incomminglist addObject:item];
[[InCommingVC incommingTable] reloadData];
} else {
[incomminglist addObject:item];
}
NSLog(@"count %i", incomminglist.count);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return incomminglist.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = @"identify_incomming";
UITableViewCell *cell = [self.incommingTable dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
IncommingItemObject *item = [incomminglist objectAtIndex:indexPath.row];
UIImageView *CountryImage = (UIImageView *)[cell viewWithTag:5010];
[CountryImage setImage:[UIImage imageNamed:item.CountryCode]];
UILabel *visitorName = (UILabel *)[cell viewWithTag:5011];
visitorName.text = item.Name;
UILabel *visitStartTime = (UILabel *)[cell viewWithTag:5012];
visitStartTime.text = item.StartTime;
return cell;
}
我想我incommingTable
从一个静态方法更新。有人能帮我吗。 TNX。
我有此错误
/用户/ zupportdesk /桌面/ MyIOSApps /聊天系统/聊天 系统/ InCommingVC.m:96:23:用于选择 'incommingTable'
没有已知方法类
,而这样做
[[InCommingVC incommingTable] reloadData];
方法2解决了我的问题。 TNX –