2013-10-15 2 views
0

Я довольно новичок в этом Native App dev - я создал приложение, которое содержит UITableViewController для отображения сообщений - все работает нормально, но для стилизации мне нужно изменить это от TableViewController до таблицы, встроенной в viewcontroller.Xcode/ObjectiveC - конвертировать UITableViewController в TableView, встроенный в UIViewController

Я сделал контроллер представления, содержащий представление таблицы и соответствующие связанные пользовательские ячейки/поля и изменил соответствующий файл заголовок, чтобы -

@interface NotificationsListTVController : UIViewController 

, но мои методы табличных уже не огнь, и я не уверены, как для их создания?

(код ниже) #pragma метка - Таблица источника данных

- (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 self.GPTNotifications.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 

static NSString *CellIdentifier = @"Cell"; 
static NSString *CellIdentifierRead = @"CellRead"; 

UITableViewCell *cell; 


notifications *n = [self.GPTNotifications objectAtIndex:indexPath.row]; 



    if (n.read == false) { 
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 



    CustomCellRead *cellReadB = (CustomCellRead *)cell; 
    cellReadB.notifTitle.text = n.notifTitleD; 
    cellReadB.notifDate.text = n.notifDateD; 
    cellReadB.notifMsg.text = n.notifMessage; 


return cellReadB; 
} 

else { 
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierRead  forIndexPath:indexPath]; 



    CustomCell *cellReadB = (CustomCell *)cell; 
    cellReadB.notifTitle.text = n.notifTitleD; 
    cellReadB.notifDate.text = n.notifDateD; 
    cellReadB.notifMsg.text = n.notifMessage; 


    return cellReadB; 

    } 


} 
+0

Убедитесь, что вы установили 'delegate and datasource' tableview. –

+0

См. Дубликат: http://stackoverflow.com/questions/9375903/how-to-interact-with-uitableview-in-uiviewcontroller – petert

ответ

2

ли параметр делегата и источник данных вашего Tableview к классу?

Что-то вроде:

self.myTableView.delegate = self; 
self.myTableView.dataSource = self; 

При создании UITableViewController это делается для вас, но если вы добавляете таблицу самостоятельно, вам нужно установить их.

также:

@interface NotificationsListTVController : UIViewController <UITableViewDelegate, UITableViewDataSource> 
1

Я делаю это так в Interface Builder:

  • Сделайте TableViewController
  • Сделайте ViewController и добавьте ContainerView к нему
  • Удаление в segued внедренный ViewController который поставляется вместе с ним
  • Выберите ContainerView и сделать соединение с viewDidLoad к вашему TableViewController
  • вы получите только один раз вариант: embed

Готово. Теперь ваш TableViewController будет отображаться в вашем ViewController.

Передайте все данные, которые вам нужны, от ViewController до TableViewController со встроенным Segue.

0

Внести следующие изменения в NotificationsListTVController.h:

@interface NotificationsListTVController : UIViewController<UITableViewDataSource,UITableViewDelegate> 

Также в NotificationsListTVController.m, не забудьте предоставить эти два заявления, а также.

tableView.delegate=self ; 
tableView.dataSource=self; 

Они необходимы, чтобы установить делегат methods.These два заявления должны быть предоставлены после инициализации вашего Tableview. Как, например:

tblView = [[UITableView alloc] initWithFrame:CGRectMake(100,200,320,420) style: UITableViewStyleGrouped]; 


    tblView.delegate = self; 
    tblView.dataSource = self; 

    [self.view addSubview:tblView]; 

Эти методы вы имеете в виду, являются делегат методы, которые не могут быть уволены непосредственно в отличие от других обычных методов.

Надеюсь, что это поможет !!!

Смежные вопросы