I have a label in a TableViewCell in which there are more than one lines of text. Initially on the label it shows only one line. I have a button on that cell. I want to expand the cell by clicking on the button upto the hight of the label's text.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"tabCell";
_cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NSManagedObject *device = [self.persons objectAtIndex:indexPath.row];
UILabel *nameLabel = (UILabel*)[_cell.contentView viewWithTag:2];
nameLabel.text = [NSString stringWithFormat:#"%#", [device valueForKey:#"name"]];
UILabel *dateLabel = (UILabel *)[_cell.contentView viewWithTag:3];
dateLabel.text = [NSString stringWithFormat:#"%#",[device valueForKey:#"date"]];
UILabel *descLabel = (UILabel *)[_cell.contentView viewWithTag:4];
//descTextView.text = [NSString stringWithFormat:#"%#",[device valueForKey:#"desc"]];
UIImageView *personImage = (UIImageView *)[_cell.contentView viewWithTag:1];
UIImage *personImg = [UIImage imageWithData:[device valueForKey:#"image"]];
personImage.image = personImg;
UIButton *viewMoreButton = (UIButton *)[_cell.contentView viewWithTag:5];
[viewMoreButton addTarget:self
action:#selector(myAction)
forControlEvents:UIControlEventTouchUpInside];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:[device valueForKey:#"desc"]
attributes:#{ NSFontAttributeName:[UIFont fontWithName:#"HelveticaNeue" size:17]}];
reqFrame=[attrString boundingRectWithSize:CGSizeMake(descLabel.frame.size.height, CGFLOAT_MAX)options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
descLabel.attributedText = attrString;
return _cell;
}
- (void)myAction{
//what to write here?
}
First of all it is not a good practice to build cell in cellForRowAtIndexPath. Use willDisplayCell instead. See here why.
Secondly to do what you want you have to set desired height in heightForRowAtIndexPath. Once this accomplished, within your button selector call to refresh specific cells using
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathOfYourCell, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
The implementation is similar:
- (void)buttonSelector
{
myLabel.text = #"YOUR TEXT";
[myLabel sizeToFit];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathOfYourCell, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
...
return yourLabel.height;
}
Anyhow need to get reference of the cell and indexPath on which the button is tapped in your myAction().
Create a private variable CGFloat newCellHeight; and initialize it to 0.0.
Let reference to the associated cell is selectedCell and selected index path is indexPathOfTappedCell.
- (void)myAction{
UILabel *descLabel = (UILabel*)[selectedCell.contentView viewWithTag:4];
[descLabel sizeToFit]; // Automatically increases the height of the label as required
newCellHeight = CGRectGetMaxY(descLabel.frame) + 10.0; // Extra padding 10.0
[tableView reloadRowsAtIndexPaths:#[indexPathOfTappedCell] withRowAnimation:UITableViewRowAnimationAutomatic];
}
Now add the following TableView delegate method in your view controller
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == indexPathOfTappedCell.section &&
indexPath.row == indexPathOfTappedCell.row ) {
return newCellHeight;
}
return 44.0; // Suppose default height is 44.0
}
you need to maintain two variables, just give tag to your button, and detect in action by its tag to reload that particular cell and another BOOL variable to detect if button touched. You should calculate height in heightForRowAtIndexPath method. I am posting code, it may help you
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if(isReadMoreButtonTouched && [indexPath row]== indexOfReadMoreButton) {
NSString *yourText = [arr1 objectAtIndex:indexPath.row]; // your text
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Avenir Next" size:14], NSFontAttributeName,
[UIColor grayColor], NSForegroundColorAttributeName,
nil]; // set custom attributes
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:yourText attributes:attributes];
CGRect paragraphRect = [attributedText boundingRectWithSize:CGSizeMake(625, CGFLOAT_MAX)
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
context:nil]; //here 625 is width of label
NSLog(#"height = %f", paragraphRect.size.height);
return paragraphRect.size.height;
}
else{
return 200; //default height taken in storyboard
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
cell.lblKB.text = [arr objectAtIndex:indexPath.row];
cell.lblDetail.text = [arr1 objectAtIndex:indexPath.row];
NSString *yourText = [arr1 objectAtIndex:indexPath.row];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Avenir Next" size:14], NSFontAttributeName,
GrayColor, NSForegroundColorAttributeName,
nil]; //your custom attributes
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:yourText attributes:attributes];
CGRect paragraphRect = [attributedText boundingRectWithSize:CGSizeMake(625, CGFLOAT_MAX)
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
context:nil];
NSLog(#"height = %f", paragraphRect.size.height);
if (paragraphRect.size.height<200) {
cell.btnMore.hidden = YES;
}
else{
cell.btnMore.hidden = NO;
}
cell.btnMore.tag = indexPath.row;
return cell;
}
// action of button click
-(IBAction)MoreBtnClicked:(id)sender {
if (!isReadMoreButtonTouched) {
isReadMoreButtonTouched = YES;
}
else{
isReadMoreButtonTouched = NO;
}
indexOfReadMoreButton = [sender tag];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];
[self.tblKB reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; //reload that cell of your tableview
}
Related
I am getting this type of data inside cell. How to set the text and detail text of cell so that both text may appear in readable format.
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.font=[UIFont fontWithName: #"Arial" size: 14.0 ];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
[cell setBackgroundColor:[UIColor whiteColor]];
UILabel *idLabel = (UILabel*)[cell.contentView viewWithTag:201];
if(!idLabel)
{
idLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 50)];
cell.textLabel.textColor = [UIColor blackColor];
idLabel.tag = 201;
[cell.contentView addSubview:idLabel];
}
idLabel.text = [arrayFiltered objectAtIndex:indexPath.row];
cell.textLabel.text = [idArray objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor grayColor];
cell.detailTextLabel.text = [descArray objectAtIndex:indexPath.row];
cell.detailTextLabel.textColor = [UIColor blueColor];
cell.detailTextLabel.numberOfLines = 2;
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
return cell;
}
The code which i have written is above.
Please help me.
We have 3 or more options to achieve this.I explain you step by step process
I create the tableView and hook up.
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
#property (strong, nonatomic) IBOutlet UITableView *tblView;
#end
ViewController.m
#import "ViewController.h"
#import "CustomCell.h" // For CustomCell using,we have to import.
#interface ViewController ()
{
NSMutableArray *idArray;
NSMutableArray *descArray;
}
#end
#implementation ViewController
In viewDidLoad method I added the objects to id desc array.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
idArray = [[NSMutableArray alloc]initWithObjects:#"INOX",#"Sathyam",#"PVR",#"IMAX",nil];
descArray = [[NSMutableArray alloc]initWithObjects:#"INOX currently operates 107 multiplexes and 420 screens in 57 cities across India",#"SPI Cinemas is an Indian multiplex chain and film production company owned by the SPI Group, headquartered in Chennai.",#"The IMAX cinema process increases the image resolution by using larger film frame;",#"PVR Cinemas is the largest and the most premium film entertainment company in India.",nil];
}
Below tableView datasource methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return idArray.count;
}
Now I have 3 options for achieving your requirement.But all these are implemented in cellForRowAtIndexPath method.
FIRST OPTION:UITableViewCellStyleDefault-If you use this, you can implement the code in cellForRowAtIndexPath like below
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *strCell = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
if(cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
}
UILabel *idLabel = [[UILabel alloc]init];
idLabel.frame = CGRectMake(15, 13, 168, 24);
idLabel.tag = indexPath.row;
idLabel.numberOfLines = 1;
idLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:18];
idLabel.textAlignment = NSTextAlignmentLeft;
idLabel.textColor = [UIColor blackColor];
idLabel.text = [NSString stringWithFormat:#"%#",[idArray objectAtIndex:indexPath.row]];
[cell.contentView addSubview:idLabel];
UILabel *descLabel = [[UILabel alloc]init];
descLabel.frame = CGRectMake(15, 47, 348, 34);
descLabel.tag = indexPath.row;
descLabel.numberOfLines = 2;
descLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:12];
descLabel.textAlignment = NSTextAlignmentLeft;
descLabel.textColor = [UIColor blueColor];
descLabel.text = [NSString stringWithFormat:#"%#",[descArray objectAtIndex:indexPath.row]];
[cell.contentView addSubview:descLabel];
return cell;
}
SECOND OPTION:UITableViewCellStyleSubtitle - If you use this, you can implement the code in cellForRowAtIndexPath like below
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *strCell = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
if(cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:strCell];
}
cell.textLabel.text = [NSString stringWithFormat:#"%#",[idArray objectAtIndex:indexPath.row]];
cell.textLabel.tag = indexPath.row;
cell.textLabel.numberOfLines = 1;
cell.textLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:18];
cell.textLabel.textAlignment = NSTextAlignmentLeft;
cell.textLabel.textColor = [UIColor blackColor];
cell.detailTextLabel.text = [NSString stringWithFormat:#"%#",[descArray objectAtIndex:indexPath.row]];
cell.detailTextLabel.tag = indexPath.row;
cell.detailTextLabel.numberOfLines = 2;
cell.detailTextLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:12];
cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
cell.detailTextLabel.textColor = [UIColor blueColor];
return cell;
}
THIRD OPTION : CUSTOM CELL - If you use Custom Cell you have to import the CustomCell.h first.After that you have to do the following things in cellForRowAtIndexPath method
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:#"cell"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil];
if(cell == nil){
cell = nib[0];
}
cell.idLabel.text = [NSString stringWithFormat:#"%#",[idArray objectAtIndex:indexPath.row]];
cell.idLabel.tag = indexPath.row;
cell.idLabel.numberOfLines = 1;
cell.idLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:18];
cell.idLabel.textAlignment = NSTextAlignmentLeft;
cell.idLabel.textColor = [UIColor blackColor];
cell.descLabel.text = [NSString stringWithFormat:#"%#",[descArray objectAtIndex:indexPath.row]];
cell.descLabel.tag = indexPath.row;
cell.descLabel.numberOfLines = 2;
cell.descLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:12];
cell.descLabel.textAlignment = NSTextAlignmentLeft;
cell.descLabel.textColor = [UIColor blueColor];
return cell;
}
I attached the screen shot of custom cell.It shows you what I have done there.
SNAPCHAT 1:idLabel
SNAPCHAT 2:descLabel
You can use heightForRowAtIndexPath method for setting row height.It is UITableViewDelegate method
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 90;
}
NOTE:Generally I set the tag for label is idLabel.tag = indexPath.row.According
to your requirement set the tag here.
I created and worked out the sample application for you.All I have done successfully.
Use cell textLable and detailTextLable to show your data like below code-
cell.textLabel.text=#"your text";
cell.detailTextLabel.text=#"your text";
idLabel overrides the position of the textlabel .
If
you want to put the id before the text , You can combine both the string and put into the textlabel.
else
use dont use textlabel and detail textlabel, create all the three labels of your own and align properly using Frame values.
Check the Height of the Cell and calculate it according to the Cell Text and number of lines of Label. And move your Font, Background Color, Line Break settings of label inside cell == nil.
Edit: to adjust three Labels you would need custom Cell or if you can concatenate it with Text Label. It all depends on your requirement.
I am trying to fill the cell.textLabel with text. That text varies in the number of lines per object in the array, and as such the cell needs to adjust in height. The cell doesn't adjust in height until the user scrolls through the list.
Here in the code.
Image of IB
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:#"Helvetica" size:17.0];
cell.textLabel.text = [kanyeLines objectAtIndex:indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellText =[kanyeLines objectAtIndex:indexPath.row];
UIFont *cellFont = [UIFont fontWithName:#"Helvetica" size:17.0];
NSAttributedString *attributedText =
[[NSAttributedString alloc]
initWithString:cellText
attributes:#
{
NSFontAttributeName: cellFont
}];
CGRect rect = [attributedText boundingRectWithSize:CGSizeMake(tableView.bounds.size.width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
return rect.size.height + 20;
}
So I'd accidentally set the datasource twice for the table instead of setting a delegate.
I have a costum UITableViewCell with an UITextView in it, but my TextView does not resize and if I scroll down the formatting of UITextView's content changes!
I have some objects in my costum cell's .h-file, but nothing else.
Here is my cellForRowAtIndexPath:
AACTickerYellowCell * cell;
NSString *cellIdentifier = #"yellowCell";
cell = (AACTickerYellowCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[AACTickerYellowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.backgroundColor = [[UIColor alloc] initWithRed:1 green:1 blue:1 alpha:1];
cell.minuteLabel.text = [[dict objectAtIndex: [[dataManager getTickerObjects] count] - 1 - indexPath.row] objectForKey:#"Minute"];
cell.textView.delegate = self;
cell.textView.text = [[dict objectAtIndex: [[dataManager getTickerObjects] count] - 1 - indexPath.row] objectForKey:#"Text"];
cell.textView.textAlignment = NSTextAlignmentLeft;
cell.textView.font = [UIFont fontWithName:#"Helvetica" size:16];
return cell;
'dict' is declared in my -viewDidLoad:.
Where are my two problems and how can I solve it?
Have you resized your cell in the - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath UITableView Delegate?
I have a tableView with custom cells. One of the objects in the cell is a textField.
The tableViewController is the textFieldDelegate.
The datasource for the table is an array of objects.
When the user tap on the textField, the tableViewController implements textField delegates methods controlling this way the data entry.
To use the data entered by user, the tableViewController implements the following:
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
CGPoint point = [textField center];
point = [self.tableView convertPoint:point fromView:textField];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
...
...
return YES
}
I spent two hours trying to figure out why indexPath.row was always wrong, it was always row+1 of what it suppose to be.
Solution: In the storyboard I move the textField to the upper portion of the cell.
Has anyone see something like this before?
Thanks.
-[UIView center] returns the center of the view's frame, which is in the view's superview's coordinate system. But -[UIView convertPoint:fromView:] expects to be given a point in the "from" view's coordinate system.
Either give it the same point, and tell it to convert from the correct view:
CGPoint point = [textField center];
point = [self.tableView convertPoint:point fromView:textField.superview];
Or give it a point in the view's coordinate system, and tell it to convert from the view:
CGRect textFieldBounds = textField.bounds;
CGPoint point = CGPointMake(CGRectGetMidX(textFieldBounds), CGRectGetMidY(textFieldBounds));
point = [self.tableView convertPoint:point fromView:textField];
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *text = [array_loaddata objectAtIndex:indexPath.row] ;
UIFont *font = [UIFont systemFontOfSize:10];
CGSize size = [(text ? text : #"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:NSLineBreakByWordWrapping];
int count = size.height + 0;
return count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array_loaddata count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier =[NSString stringWithFormat:#"Cell%d",indexPath.row] ;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
NSString *text = [array_loaddata objectAtIndex:indexPath.row] ;
UIFont *font = [UIFont systemFontOfSize:10];
CGSize size = [(text ? text : #"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:NSLineBreakByWordWrapping];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(46, 0, size.width, size.height)];
label.numberOfLines = 0;
label.textColor = [UIColor grayColor];
label.lineBreakMode = NSLineBreakByWordWrapping;
label.text = (text ? text : #"");
label.font = font;
label.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:label];
[label release];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
link==http://mobile.tutsplus.com/tutorials/iphone/iphone-json-twitter-api/
/*
NSString *appurl =[NSString stringWithFormat:#"xx"];
appurl = [appurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:appurl]];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
*/
}
I have problem with my UItableview that when I use viewWillAppear for retrieving updated data each time table is viewed this gives me exception .
Please can any one help me on how to refresh tableview in viewWillAppear so that it will be updated before CellforrowAtindexPath is called ?
Here is my code for viewWillAppear:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self.tableView reloadData];//table was filled in viewDidLoad.
}
Here is CellforrowAtindexPath` : (The exception is on mainArray which means that there is conflict in updating table through viewWillAppear and calling cell ):
//Methods to retrive all selected words , thier sound and picture for the mother
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifer = #"Cell";
UITableViewCell *cell= [ tableView dequeueReusableCellWithIdentifier:CellIdentifer];
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifer];
}
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
UILabel *label ;
label=(UILabel *)[cell viewWithTag:1];
NSString *value = [[self.mainArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
label.text = value;
label.textAlignment=NSTextAlignmentRight;
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
//self.tableView.separatorColor = [UIColor blackColor];TRY TO SEPARETE BETEWEEN LINES OF TABLE
UIButton *butt =(UIButton *)[cell viewWithTag:2];
NSString *value2 = [[self.mainArray2 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
butt.restorationIdentifier= value2;
[butt addTarget:self action:#selector(play:) forControlEvents:UIControlEventTouchUpInside];
NSString *value3 = [[self.mainArray3 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:value3];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
return cell;
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;{
return self.mainArray.count;
}
if count is 0, table view won't call the other functions.