【发布时间】:2012-04-13 11:27:21
【问题描述】:
我正在尝试在我的第一个视图中显示一个列表,所以在 first.h 中添加了这个:
#import <UIKit/UIKit.h>
@interface argospineFirstViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray *Journals;
IBOutlet UITableView *myTableView;
}
@property (nonatomic,retain) NSMutableArray *Journals;
@property (nonatomic, retain) UITableView *myTableView;
@end
然后我在我的 first.m 上添加了这个:
@implementation argospineFirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Journals=[NSMutableArray arrayWithObjects:@"journal1",@"journal2",nil];
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
cell.text=[Journals objectAtIndex:indexPath.row];
return cell;
}
我是新手,所以我真的不知道我必须建立什么样的联系,我也在使用一个故事板,其中一个 tableview 放在第一个视图上。 我有什么要添加到代表的吗? 有什么帮助吗? 谢谢你的时间
【问题讨论】:
-
您是否在 .xib 文件中建立了连接?
-
@M.Sharjeel 我没有任何.xib 文件我正在使用情节提要
-
在下面试试我的答案并更新我!
-
作为一般注释,变量名的第一个字母不要使用大写字母。例如,使用期刊而不是期刊。
标签: iphone ios uitableview uitabbarcontroller