首页 文章

数据未显示在UITableView下方按钮中

提问于
浏览
0

我为Iphone创建了一个UI,它在tableview上方有一个按钮和标签 . 问题是尽管在cellForRowAtIndexPath方法中设置了数据,但数据不会显示在表中 . 我明白了:
enter image description here

这是我的第三个标签控制器的代码 . Headers :

#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是全屏) .

我在这做错了什么?

enter image description here
@Jennis:我尝试了你的解决方案,现在可以看到表格中的数据,但上面的部分被挤压成这样:

1 回答

  • 0

    我相信你可以做到

    [self.view addSubview:myTableView]; [self.view sendSubviewToBack:myTableView] .

    希望能帮助到你

相关问题