M
M
MelkoV2011-06-27 10:44:14
iOS
MelkoV, 2011-06-27 10:44:14

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 answer(s)
I
Infernal, 2011-06-27
@Infernal

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];
    }
    //теперь выполняем настройку ячейки под наши данные
}

3. If there are several sections in the table, then you also implement
- numberOfSectionsInTableView:
4. In IB, set the dataSource property of the table to your controller.
Thus, get a static table. To dynamically add/delete cells to the tableView subsequently call the table methods:
– insertRowsAtIndexPaths:withRowAnimation:
– deleteRowsAtIndexPaths:withRowAnimation:
– insertSections:withRowAnimation:
– deleteSections:withRowAnimation:
Calls to these methods are between [tableView beginUpdates] and [tableView endUpdates]
Important. The DataSource must be ready to process the changed data before calling these methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question