数据未在按钮下方的UITableView中显示
|
我为Iphone创建了UI,该UI在tableview上方有一个按钮和标签。问题是尽管在cellForRowAtIndexPath方法中进行了设置,但数据仍未显示在表中。
我得到这个:
这是我的第三个选项卡的控制器代码。标头:
#import <UIKit/UIKit.h>
@interface ThirdView : UIViewController <UITableViewDelegate,UITableViewDataSource> {
//model
NSMutableArray *podatki;
//view
UITableView *myTableView;
}
@property(nonatomic,retain) NSMutableArray *podatki;
@property(nonatomic,retain) UITableView *myTableView;
-(IBAction)pritisnuGumb:(UIButton *) sender; //
@end
实现方式:
#import \"ThirdView.h\"
@implementation ThirdView
@synthesize podatki;
@synthesize myTableView;
-(void)viewDidLoad{
myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
myTableView.delegate = self;
myTableView.dataSource = self;
myTableView.autoresizesSubviews = YES;
podatki = [[NSMutableArray alloc] init];
[podatki addObject:@\"Sunday\"];
[podatki addObject:@\"MonDay\"];
[podatki addObject:@\"TuesDay\"];
[super viewDidLoad];
//self.view = myTableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [podatki count];
}
-(IBAction)pritisnuGumb:(UIButton *) sender {
NSLog(@\"buca\");
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @\"Cell\";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.numberOfLines = 4;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *naslov = [podatki objectAtIndex:indexPath.row];
cell.textLabel.text = naslov;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@\"kliknu na vrstico\");
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn\'t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren\'t in use.
}
#pragma mark - View lifecycle
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)dealloc {
[podatki release];
[super dealloc];
}
@end
如果我取消注释行\“ self.view = myTableView; \”,则会获得带有数据的tableview,但是其上方的标签和按钮消失(tableview为全屏显示)。
我在这里做错了什么?
@詹妮斯:
我尝试了您的解决方案,表格中的数据现在可见,但上部被挤压成这样:
没有找到相关结果
已邀请:
1 个回复
臀博