Hosni
Hosni

Reputation: 668

UITabBarController with UITableView

i am trying to display a list on my first view so added this in the first.h :

    #import <UIKit/UIKit.h>

    @interface argospineFirstViewController : UIViewController
    <UITableViewDelegate,UITableViewDataSource>
   {
NSMutableArray *Journals;
IBOutlet UITableView *myTableView;
    }

   @property (nonatomic,retain) NSMutableArray *Journals;
   @property (nonatomic, retain) UITableView *myTableView;
    @end

and then i added this on my first.m :

  @implementation argospineFirstViewController


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Journals=[NSMutableArray arrayWithObjects:@"journal1",@"journal2",nil];
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
 }
- (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];
}
cell.text=[Journals objectAtIndex:indexPath.row];
return cell;

}

I am newbie so i don't really know what kind of connections i have got to make, i am also using a storyboard with a tableview dropped on the first view. is there something i have to add to the delegate? Any help? Thank you for your time

Upvotes: 1

Views: 818

Answers (5)

jyoti
jyoti

Reputation: 29

you use cell.text for show the data i think its not work in tableview just try this line:-

cell.textlabel.text=[yourArrayname objectatindex:index.row];

no need to connect delegate you already define in protocol.

Upvotes: 0

Justin Paulson
Justin Paulson

Reputation: 4388

Right click on the tableView in the storyboard. You will see "delegate" and "dataSource" under Outlets. Drag the bubble on the right of those to the view controller icon at the bottom of the view. This will make your viewcontroller the delegate and datasource for the table view if you don't want to do it programmatically.

Upvotes: 1

Deviator
Deviator

Reputation: 688

Do not make property of your table view object.

Also,

in viewDidLoad method write:

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

Tell me if it helps!

Upvotes: 0

mhunturk
mhunturk

Reputation: 296

in IBOutlet set delegete and datasource of the tableview to filesOwner

Upvotes: 0

Phillip Mills
Phillip Mills

Reputation: 31026

Use initWithStyle instead of initWithFrame for creating your cell.

In your storyboard, select your table view and open the Connections Inspector. Make sure that the delegate and datasource connections are linked to your argospineFirstViewController object.

Upvotes: 0

Related Questions