Answer the question
In order to leave comments, you need to log in
How to add elements to UITableView?
Good afternoon. I am developing for an iPhone for the first time, I have many questions, but now I am more concerned about one thing - how to fill the table with information?
I have a Tab application, on one tab (separate view) I placed a UITableView, associated it with a class, created an IBOutlet UITableView *myTable variable, associated the variable with a table in IB. I don't know what to do next :(
Answer the question
In order to leave comments, you need to log in
1. Add the UITableViewDataSource
protocol to your controller
2. Be sure to implement the following methods:
- tableView:numberOfRowsInSection:
- tableView:cellForRowAtIndexPath:
The latter is usually implemented according to the following pattern:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* reuseId = @"ReuseID";
//сначала пытаемся найти ранее созданную, но не используемую ячейкц
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
if (!cell) {
//если не нашили, создаем новую
cell = [[UITableViewCell alloc] initWithReuseIdentifier:reuseId] autorelease];
}
//теперь выполняем настройку ячейки под наши данные
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question