【发布时间】:2013-05-19 18:15:03
【问题描述】:
您好,我正在尝试在我的 uiviewcontroler 上使用 tableview 在我的 .h 中,我输入了以下代码:
@interface SecondViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *myTableView;
}
@property (nonatomic, retain) IBOutlet UITableView *myTableView;
在我的 .m 上:
我修改了我的代码,但现在它说我的 Response_array 未声明,并且在对象类型 uitableviewcell 上找不到 myTablevView
@synthesize myTableView;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_responseArray count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] init];
}
NSString *cellValue = [_responseArray objectAtIndex:indexPath.row];
[cell.textLabel setText:cellValue];
return cell;
}
这是我的 Response_array
NSArray* Response_array = [json objectForKey:@"avenidas"];
【问题讨论】:
-
错误出现在哪一行?
-
在 -(UITableViewCell *)myTableView 行
-
-(UITableViewCell *)myTableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 将不会被调用,并且会导致错误,因为委托方法声明不正确。它应该是 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 另外,请检查以确保在方法主体之前和之后都有一个开始和结束括号 {}。
-
谢谢,但现在我有其他错误
-
@darkjuso,没问题!我很高兴这有帮助。我在下面提供了答案。
标签: objective-c uitableview uiviewcontroller tableview