Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Table View

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 458
    Comment on it

     

    Table view is one of the most frequent iOS app UI element. In iOS many of the apps utilize tableview to exhibit a list of data. Special features of tableView include headers, footers, rows, and section. It provides a list of options further selecting on it we can get more information related to the selection on the TableView.
    TableView uses UITableViewCell to display the rows in the table..
    TableView consists of number of cells in which the content to be shown is displayed . The cells can be scrolled in the vertical direction..

    Thus we can say that tableView is a versatile interface for managing and interacting with collections of data.

    Here is an example of using UITableView showing images and titleLabel..

    In the storyboard drag a TableView from the object gallery and place it on the ViewController. After that drag a TableViewCell and place it on the UITableView. Select the cell of the table and give its identifier.
    Now make a new file which is a subclass of UITableViewCell and assign that class to the cell.. Here that cell class is DemoTableViewCell.
    In the cell class make two outlets of UIImageView and a UILabel and connect them to the UIImageView and UILabel dragged in the cell in MainStoryboard :-

    1. @property (weak, nonatomic) IBOutlet UIImageView *imgView; // outlet of UIImageView
    2. @property (weak, nonatomic) IBOutlet UILabel *lblMessage; // outlet of UILabel

    Now in your ViewController.m file implement the following code :-

    1. #import "ViewController.h"
    2. #import DemoTableViewCell.h" // import the Cell Class
    3.  
    4. @interface ViewController ()
    5. {
    6. NSArray *arrofText; // array of text
    7. NSArray *arrOfImages; // array of images
    8. }
    9.  
    10. @end
    11.  
    12. @implementation ViewController
    13.  
    14. -(void)viewWillAppear:(BOOL)animated{
    15. arrofText = [[NSArray alloc]initWithObjects:@"star",@"cross",@"rose1",@"cross", nil];
    16. arrOfImages=[[NSArray alloc]initWithObjects:@"index.png",@"index.png",@"index.png",@"cross.png", nil];
    17. }
    18.  
    19. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    20. return arrofText.count;
    21. }
    22.  
    23. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    24. NSString *cellIdentifier = @"UseOfTable";
    25. NewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    26. [cell.lblMessage setText:[arrofText objectAtIndex:indexPath.row]]; // set text in the label from the array of text
    27. [cell.imgView setImage:[UIImage imageNamed:[arrOfImages objectAtIndex:indexPath.row]]]; // // set image in the label from the array of images
    28. return cell;
    29. }
    30.  
    31. @end
    32.  

    After implementing all this when you build your project it will not display anything.. Reason is the DELEGATE and DATASOURCE of tableView is not set..
    For displaying the content in the TableView the tableView should have a Datasource and for managing the appearance and behavior it should have Delegate.
    Set the delegate and datasource and then it’s done !!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: