Using UITableViewCell in a UITableView

I’m a little confused with something. I’m trying to create a custom cell and I want to use the interface builder way.

The normal way I create a table is to have the table as:

  • Long press and single click on button
  • Sync core data database/ .sqlite file to Dropbox
  • JavaScript on iOS: opening an HTML select element
  • What is the correct way to proceed with this bool?
  • UIEdgeInsetsMake creating a weird band on the cell, and I don't know how to fix it
  • Swift Use of undeclared type 'GGLInstanceIDDelegate'
  • .h

    @interface AssessList : UIViewController {
    
        IBOutlet UITableView *tblAssessList;
    }
    
    @property(nonatomic, retain) UITableView *tblAssessList;
    
    @end
    

    .m

    - (NSInteger)
    numberOfSectionsInTableView:(UITableView *)tableView {
        return groupArray.count;
    }
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
         return totalArray.count;
    }
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        }
    
    
    
        cell.textLabel.text = @"I am the text....";
    
            return cell;
    }
    

    Now i’ve created a new class for the cell and I think I understand how to put that in. But can I leave the .h as

    @interface AssessList : UIViewController
    

    or does the class/nib with the full table on it have to be a UITableViewController?

    Tom

    6 Solutions Collect From Internet About “Using UITableViewCell in a UITableView”

    does the class/nib with the full table on it have to be a
    UITableViewController?

    No. A UITableViewController is just a convenience UIViewController subclass which has a UITableView and is already setup as its delegate/datasource (it is declared as conforming to the UITableViewDelegate and UITableViewDatasource protocols), it also has pre-filled method implementations for these protocols in the template implementation file which Xcode generates for you. You can just as well do all of this yourself, I often do.

    You should however make an IBOutlet for your UITableViewCell so that you can load it from the nib file (see the Loading Custom Table-View Cells From Nib Files in the Table View Programming Guide).

    If you want to do in the Interface Builder Way, then create an xib (view xib). Drag and drop a UITableViewCell object from the obj palette. Customize it as you wish. In the tableView:cellForRowAtIndexPath: method, do this:

    UITableViewCell * aCell = [tableview dequeueReusableCellWithIdentifier:@"SomeIdentifier"];
    if (aCell == nil)
    {
    
    
        NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"CustomCellNibName" owner:self options:nil];
    
        for (NSObject *anObj in arr) {
    
            if([anObj isKindOfClass:[UITableViewCell class]]) {
    
                aCell = (UITableViewCell *)anObj;
    
            }
        }
    }
    

    The identifier for the tableviewcell can be set in the IB.

    you can use this sample code describe hear.

    http://ijoshsmith.com/2011/07/16/creating-a-custom-uitableviewcell-in-ios-4/
    

    or You can use this link also

    http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
    

    I guess it should be sub class of UItableViewCell

    i.e.

    @interface AssessList : UITableViewCell
    

    When you want a custom tableview cell you will also need a subclass of UITableViewCell..

    A tutorial can be found on this blog

    Keep in mind that quite a few things can be done without creating a custom cell, this includes adding the switch to make your tableview look like the one from settings.app, to the way the iPod displays songs.

    In the assessList Class you are using the custom cell created in otherviewController (UITableViewCell subclass) so there is no need to change this line

    @interface AssessList : UIViewController

    Note:- the otherviewController should be a subclass of UITableViewCell