UITableView как подпредставление? - PullRequest
3 голосов
/ 24 августа 2010

Возможно ли это? Я просто хочу небольшую таблицу в моем текущем представлении ... вот что я пытаюсь сделать:

.h файл

#import <UIKit/UIKit.h>


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

@property (nonatomic, retain) UITableView *ingredientsTable;

@end

.m файл У меня есть методы делегата и источника данных и этот код:

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

Приложение не падает, но не показывает таблицу. На данный момент я все определенно настроил согласно:

#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;
}

Что я делаю не так? Спасибо

Ответы [ 2 ]

3 голосов
/ 24 августа 2010

Попробуйте вызвать -reloadData в табличном представлении после добавления его в качестве подпредставления.

Кроме того, как настроен вид? Это создается в XIB или через -loadView?

0 голосов
/ 24 августа 2010

Вы не забыли добавить [window addSubview:[IngredientsRootView view]]; к вашему делегату приложения?

И, кстати, вместо того, чтобы наследовать от UIViewController, вы можете просто наследовать от UITableViewController, и вы получите всю эту функциональность для вас без добавления кода.

...