0

i am working in an project in which i have to create a facebook like newsfeed view after hours of R&D i choose to use prototype cells in UITableView for newsfeed view now the problem in row 1 i have to show only single information whereas in second cell i have to pass an array which have multiple elements like in fb wall. in which the content of second cell is changes as par array size and first cell remain unchanged. please suggest me any other way how can i perform all this.

currently i am using the following code in tableview delegate methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier;
    if (indexPath.row == 0)
    {
        identifier = @"OneCellId";
    }
    else if (indexPath.row == 1)
    {
        identifier = @"OtherCellId";
    }

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];


    return  cell;
}

enter image description here

Abhi
  • 243
  • 4
  • 19
  • Possible duplicate of [2 different types of custom UITableViewCells in UITableView](http://stackoverflow.com/questions/1405688/2-different-types-of-custom-uitableviewcells-in-uitableview) – Larme Sep 09 '16 at 12:12
  • i saw that question too but didn't get the solution – Abhi Sep 09 '16 at 12:15
  • i don't understand the question, you say you want 2 different cells and then show code and a screenshot that use 2 different cells? – Wain Sep 09 '16 at 12:16
  • What's your question then? The previous one response mainly to: How do I manage to set properties of different cells according to my datasource. Like `myCell.propertyOnlyAvailableOnPrototype1= "Blablabla";` and `myCell.propertyOnlyAvailableOnPrototype2= "Hello There";`. So what's your issue? – Larme Sep 09 '16 at 12:17
  • i want the content in second cell will repeat according to array but the first cell remain same or static – Abhi Sep 09 '16 at 12:19
  • if first cell is remain same then put in the section and second section will be as per your requirement – Pushp Sep 09 '16 at 12:19
  • i set the tag for both the cells as 0 and 1 but now i have no idea how to define the number of rows in section – Abhi Sep 09 '16 at 12:20
  • maintain two cell identifier set for these scenario – Arun Sep 09 '16 at 12:24
  • @Spynet i already create 2 cellIdentifier for both cells – Abhi Sep 09 '16 at 12:25
  • where is your height for row index path method – Arun Sep 09 '16 at 12:29
  • -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100; } – Abhi Sep 09 '16 at 12:31
  • You have given the static height 100, put that too 200 – Arun Sep 09 '16 at 12:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/122994/discussion-between-spynet-and-abhi). – Arun Sep 09 '16 at 12:34
  • refer this link, http://stackoverflow.com/questions/18153702/uitableview-mix-of-static-and-dynamic-cells Hope it will help – KAR Sep 09 '16 at 13:20

2 Answers2

2

Have your static view(referring to first cell) in HeaderSection.

Rajesh73
  • 342
  • 1
  • 6
  • 16
0

Yes you can use prototype cells as you are using, just dequeue as per your requirement and for dynamic height you can refer UITableViewCell with dynamic height iOS

Community
  • 1
  • 1
Tarun Seera
  • 4,212
  • 4
  • 27
  • 41