UITableView als eine Untersicht?

Ist das möglich? Ich möchte nur eine kleine Tabelle in meiner aktuellen Ansicht... hier ist, was ich versuche zu tun:

.h-Datei

#import <UIKit/UIKit.h>


@interface IngredientsRootView : UIViewController <UITableViewDelegate, UITableViewDataSource> {
 UITableView *ingredientsTable;
}

@property (nonatomic, retain) UITableView *ingredientsTable;

@end

.m-Datei habe ich delegieren und Datenquellen-Methoden und-code:

ingredientsTable = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 300, 300) style:UITableViewStylePlain];
 [ingredientsTable setDelegate:self];
 [ingredientsTable setDataSource:self];
 [self.view addSubview:ingredientsTable];

Die app stürzt nicht ab, aber es zeigt nicht an einen Tisch. Im moment habe ich einfach alles ein, was definitiv als pro:

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    //Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //Return the number of rows in the section.
    return 10;
}


//the appearance of table view cells.
- (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] autorelease];
    }

    //Configure the cell...
 cell.textLabel.text = @"Hello";

    return cell;
}

Was mache ich falsch? Dank

  • Ich denke, es hängt davon ab, wo Sie initialisieren der tableView, sind Sie in der initWithNib: Methode des Controllers?
  • oh, tut mir Leid.... keine viewDidLoad 🙂
  • link Versuch es als IBOutlet im Interface Builder, und lassen Sie die Initialisierung zu ihm, nur halten Sie die Stellvertretung/datasource-Teil
Schreibe einen Kommentar