0

I want to make paging swipe left and right using UIScrollView after view detailController.

First, main.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    OZDetailViewController *detailViewController = [[OZDetailViewController alloc] initWithNibName:@"OZDetailViewController" bundle:nil];
    detailViewController.arrDetailNews = [_arrNews objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:detailViewController animated:YES];

    OZDetailViewController *arrNewsAll = [[OZDetailViewController alloc] initWithNibName:@"OZDetailViewController" bundle:nil];
    arrNewsAll.allNewsArray = _arrNews;
    [self.navigationController pushViewController:arrNewsAll animated:YES];
}

When I selected content in tableviewcell, arrDetailNews can loaded in method viewDidLoad() and cellForRowAtIndexPath(). But arrNewsAll cannot loaded in method cellForRowAtIndexPath().

This is my detailViewController.h:

@property (nonatomic, copy) NSArray *allNewsArray;

And detailViewCOntroller.m:

@synthesize allNewsArray;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.separatorColor = [UIColor clearColor];
    NSLog(@"dataArray: %@", allNewsArray);
}

- (int)numberINSectionsInTableView: (UITableView *)tableView
{
    return 1;
}

- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"dataArrayCell: %@", allNewsArray);

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"New Cell"];
    }

    if(indexPath.row != self.arrDetailNews.count-1){
        UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 44, 320, 2)];
        line.backgroundColor = [UIColor whiteColor];
        [cell addSubview:line];
    }

    tableView.allowsSelection = NO;
    cell.textLabel.text = [NSString stringWithFormat:@"%u", indexPath.row];

    if (indexPath.row==0) {
        cell.textLabel.text = @"1st";
    }
    if (indexPath.row==1) {
        cell.textLabel.text = @"2nd";
    }
    if (indexPath.row==2) {
        cell.textLabel.text = @"3rd";
    }
    return cell;
}

If allNewsArray can loaded in cellForRowAtIndexPath() I can continue next step for paging with UIScrollView. Note, numberOfRowsInSection I set to 4 because I need 4 rows (custom view).

4
  • Can you check if you connected correctly the delegate and the datasource to the view controller? Commented Aug 8, 2014 at 23:25
  • hi luca Bartoletti. yes i was connected my tableView to delegate and datasource. but i have two array in didSelectRowAtIndexPath 1st for selected array 2nd for all array. for the 1st array that is not issue i can parse the array. but in the 2nd array i cannot NSLog in method cellForRowAtIndexPath. any idea? my goal is i wan to paging content with UIScroolView Commented Aug 9, 2014 at 8:04
  • Can you try to rewrite the question? Commented Aug 9, 2014 at 11:14
  • hi luca i was rewrite my question. maybe you can help me :) Commented Aug 9, 2014 at 13:51

1 Answer 1

1

Assuming you setup your delegate & dataSource outlets correctly from xib/storyboard, you still need to specify the number of rows per section (or number of sections).

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return allNewsArray.count;
}

Alternatively, the method for number of sections is:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
Sign up to request clarification or add additional context in comments.

1 Comment

hi jakaenberg. yes i was connected my tableView to delegate and datasource in my xib. but i have two array in didSelectRowAtIndexPath 1st for selected array 2nd for all array. for the 1st array that is not issue i can parse the array. but in the 2nd array i cannot NSLog in method cellForRowAtIndexPath. any idea? my goal is i wan to paging content with UIScroolView

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.