【发布时间】:2012-03-18 22:51:19
【问题描述】:
我想在 UIViewController 中放置一个 tableView,因为我需要在视图顶部有一个工具栏,因此我不能使用 tableViewController。我创建了一个 tableView 类,并将我认为需要的功能放入其中,但我一定遗漏了一些东西,或者在某处放了一些错误。
.h
import <UIKit/UIKit.h>
@interface TestTV : UITableView
@property(strong,nonatomic)NSArray *arr;
@end
.m
#import "TestTV.h"
@implementation TestTV
@synthesize arr = _arr;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
_arr = [[NSArray alloc]initWithObjects:@"HEJ",@"FOO", nil];
return _arr.count;
}
- (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];
}
NSString *cellValue = [_arr objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
@end
【问题讨论】:
标签: objective-c ios uitableview uiviewcontroller xcode4.2