这是我的场景, 我有ViewController1和Class1(服务类)。UITableView变成了无从服务器得到响应后
我在nib中通过在ViewController1中设置委托和数据源来加载tableView。在viewDidLoad中,我在另一个类(Class1)中调用了一个networkCall函数。在Class1中,获得响应后,它将传递一组响应数据给ViewController1中的一个函数,在这里数据应该填充到tableview中。
我已经在xib中连接了数据源和委托。 问题: 当我在ViewController1中得到一个数组响应时,UITableView变为零,我无法使用reloadData,但是我的数组包含来自服务器的项目列表。
这里是我的代码
ViewController1
- (void)viewDidLoad
{
[super viewDidLoad];
ClassA *class = [[ClassA alloc]init];
[class getResponse];
}
//This method is calling from ClassA using delegate
-(void)responseData:(NSArray*)arrayList
{
//arrayList have response data
[tableView reloadData];//here tableView becomes nil.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"array count %d",array.count);//has number of items(for me, its 3).
return array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TableView";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"dsds";
return cell;
}
的tableView呼吁第一次。在接口
在ViewController1 ,我设置的协议
<UITableViewDelegate,UITableViewDataSource>
'(无效)responseData'方法尝试'yourTableView = [[UITableView的页头] INIT]; [yourTableView reloadData];' – RomanHouse
你似乎没有在你的' - (void)viewDidLoad'中设置你的视图控制器作为'ClassA * class'的委托。你到底该如何从'ClassA'调用' - (void)responseData:(NSArray *)arrayList'? – Vladimir
@Vladimir: id view1 = [[ViewController1 alloc] init]; [view1 responseData:objects]; 这就是我打电话 –
Anish