UITableView issue in iPad? - ios

I am working in a iPad application. I'm using a UITableView to create a table and insert 2 UIImageViews in each cell. I tried to set image in both UIImageViews, but index path values start from 0,1,2,3,4 etc...
Each UIImageView has same image in first cell. How to fix this issue?
Example:
- (void)viewDidLoad
{
[super viewDidLoad];
// ImageArray have 5images;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [ImageArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
imgView1.image = [imageArray objectAtIndex:indexPath.row];
imgView2.image = [imageArray objectAtIndex:indexPath.row];
}

After formatting your code it becomes clear that you are assigning the same image from the array to each of the two image views. You will need an imageViewArray that has the double amount of members.
Also, you should not check for the count of your image array but for the row of your index path.

Related

How to select the UITableViewCell from top to bottom in objective c?

I am new to Objective C. I am having the UITableView in that I have to select the tableview cell from top to bottom also without selecting the first cell the second cell won't be selected and the user won't able to select the in-between cells also.can anyone help me how to solve this?
I added the example image here if the user selected the first cell the second cell want to enable and if the user selects the second cell the third cell want to enable remaining cells want to disable.
- (void)viewDidLoad {
[super viewDidLoad];
self.colors = [[NSArray alloc] initWithObjects: #"Red", #"Yellow", #"Green",
#"Blue", #"Purpole", nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.colors count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [self.colors objectAtIndex:indexPath.row];
return cell;
}
Your question is not clear, Hope you have an issue with making multiple cell selection:
Allow UITableView to select multiple cells by tableView.allowsMultipleSelection = true;. And then a user can select any number of cells in the table.
Using this way you can able to select the current row and enable next row for selecting. You need to handle another way to disable others row in cellForRowAtIndexPath method.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.checkMark.selected = YES;
NSString *cellText = cell.textLabel.text;
if(self.colors.count < indexPath.row+1 ){
NSIndexPath *nextIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:0];
UITableViewCell *nextCell = [tableView cellForRowAtIndexPath:nextIndexPath];
nextCell.checkMark.userInteractionEnabled = YES;
//OR
nextCell.userInteractionEnabled = YES;
}
}

UITableView Image in the Cell Shrinks

The images in the tableview cell shrinks as soon as they are scrolled. They resize to the wanted size by reload.
The big stars have the size I want. The smaller ones appears during scrolling or on touch.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = #"Cell";
NSArray *sectionData = self.dataSource[indexPath.section];
SHFriendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
[cell updateWithData:sectionData[indexPath.row]];
return cell;
}
- (void)updateWithData:(SHFriendTableCellData *)data {
self.friendImage.contentMode = UIViewContentModeScaleToFill;
self.friendImage.image = data.image;
self.nameLabel.text = data.name;
}
Changing the content mode has no effect.
I had a double reference to the image view.
After deleting the issue was gone after I deleted the double reference.

UITableView Cell ImageView issue [duplicate]

This question already has answers here:
Is there a way to make UITableView cells in iOS 7 not have a line break in the separator?
(17 answers)
Closed 8 years ago.
Hi
I have a UITableView in my class and when i tried to load the contents am getting a screen like this
Below the white box am not able to see the horizodal separator line , Please help me.
My code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; //count of section
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [names count]; //count number of row from counting array hear cataGorry is An Array
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = #"service";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier]
;
}
// Here we use the provided setImageWithURL: method to load the web image
// Ensure you use a placeholder image otherwise cells will be initialized with no image
cell.imageView.frame=CGRectMake(5,10,50,60);
cell.imageView.image=[imaages objectAtIndex:indexPath.row];
cell.textLabel.text = [names objectAtIndex:indexPath.row];
cell.backgroundColor=[UIColor clearColor];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
write in your view did load
In iOS 7 and later, cell separators do not extend all the way to the edge of the table view.This property sets the default inset for all cells in the table, much like rowHeight sets the default height for cells. It is also used for managing the “extra” separators drawn at the bottom of plain style tables.
// Do any additional setup after loading the view.
if ([_tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[_tableView setSeparatorInset:UIEdgeInsetsZero];
}

UIImage movement on UITableView when selecting cell or scrolling

I feed a UITableView with a list of names and images from a JSON. "SDWebImage" handles images download. It works OK apart from the fact that the images move to the left when the user selects a row or when scrolls the table view.
Two screen captures to show the issue.
Interface Builder setup
Implementation is pretty standard:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
if (cell == nil ) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"Cell"];
}
cell.textLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:#"marca"];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
[cell.imageView setImageWithURL:[NSURL URLWithString:[[array objectAtIndex:indexPath.row]objectForKey:#"photoUrl"]]placeholderImage:[UIImage imageNamed:#"placeholder.png"] ];
return cell;
}
What can I do to stop images moving?
I've just had a similar issue on an app and found it was because I was re-using UITableViewCells default imageView IBOutlet.
After creating my a new IBOutlet, called something other than imageView, and hooking it up it resolved the issue.

UITableview grouped style only showing one value from array?

MY UITableview Group style only showing one value from the array of 4 elements.
in viewdidload i add following array
_displayThemeItems=[[NSArray alloc]initWithObjects:#"Default",#"Night",#"Sepia" ,#"Blue" ,nil];
_displayThemeIcons=[[NSArray alloc]initWithObjects:[UIImage imageNamed:#"day.png"],[UIImage imageNamed:#"night.png"],[UIImage imageNamed:#"sepia.png"], [UIImage imageNamed:#"blue.png"],nil];
and my table delegate methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_displayThemeItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=#"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// No cell available - create one.
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];}
NSLog(#"rray%#",_displayThemeItems);
cell.textLabel.text = [_displayThemeItems objectAtIndex:indexPath.row];
cell.imageView.image=[_displayThemeIcons objectAtIndex:indexPath.row];
return cell;
}
Your code look fine to me, the only the only reason that I can think amy effect the result you see is how you set up your table view.
Make sure that your table view frame is bug enough to show the 4 items, and make sure you set the tabe view data source.
Add the "}" just before the return such that the code where you set the title and image comes under the "if" statement.

Resources