Данные не отображаются в UITableView ниже кнопки - PullRequest
0 голосов
/ 15 апреля 2011

Я создал пользовательский интерфейс для Iphone с кнопкой и надписью над таблицей.Проблема в том, что данные не отображаются в таблице, несмотря на установку в методе cellForRowAtIndexPath.Я получаю это: enter image description here

Это мой код для контроллера третьей вкладки.Заголовок:

#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;"я получаю табличное представление с данными, но ярлык и кнопка над ним исчезают (табличное изображение полноэкранное).

Что я здесь не так делаю?

enter image description here @Jennis: Я попробовал ваше решение, и данные внутри таблицы теперь видны, но верхняя часть сжата так:

1 Ответ

0 голосов
/ 15 апреля 2011

Я считаю, что вы можете сделать как

[self.view addSubview: myTableView];

[self.view sendSubviewToBack: myTableView].

надеюсь, это поможет

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...