New*_*one 10 iphone uitableview
我需要在一个UIView上有两个UITableViews.我可以使用它,这是代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [contentOne count]; // sets row count to number of items in array
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *firstValue = [[NSString alloc] initWithFormat: @"Row %i% %", indexPath.row+1 ];
NSString *secondValue = [contentOne objectAtIndex:indexPath.row];
NSString *cellValue = [firstValue stringByAppendingString: secondValue]; // appends two strings
[cell.textLabel setText:cellValue];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的方法.任何人?如果我可以为每个UITableView命名一个不同的名称,但它不会让我在没有崩溃的情况下编辑tableView.
Dav*_*des 28
所以你需要一些方法来区分两者tableView- 你可以将"tag"属性设置为不同的值,或者在视图控制器上有一个指向每个视图的属性
@property (nonatomic, retain) IBOutlet UITableView *tableView1;
@property (nonatomic, retain) IBOutlet UITableView *tableView2;
Run Code Online (Sandbox Code Playgroud)
然后将它们连接到界面构建器中的每个视图...
然后在你的视图控制器方法中你可以做到
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (tableView == self.tableView1) {
return 37;
} else if (tableView == self.tableView2) {
return 19;
} else {
// shouldn't get here, use an assert to check for this if you'd like
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20624 次 |
| 最近记录: |