I'm trying to display a UITableView with a list of artists who read from Last.fm API. I store all the artists in an array, then I show a table with your name and your picture.
Initially the photos look good, but when I do scroll the images are very small.
This is the initial appearance:
This is the appearance after scrolling, with the problem:
This is my code for create the cells:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TopArtistCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
JSCArtist *artist = self.artists[indexPath.row];
cell.textLabel.text = [artist name];
[cell.imageView setImageWithURL:[NSURL URLWithString:[[artist photo] thumbnail]] placeholderImage: [UIImage imageNamed:#"default_photo.jpeg"]];
return cell;
}
The default imageView for a UITableView acts a little odd. I would just create a custom UITableViewCell subclass and do your own layout.
Related
I am a beginner in iOS development. I face a problem where I need little help.
I wrote a small program to learn custom UITableViewCell. It just works well at beginning; after that, when I slide the view, it changes size of the cell. I am confused about where I might be going wrong. The ContentView have only one view which is UIImageView.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HWHomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:#"HWHomePageCell"];
if (cell == nil)
{
cell = [HWHomePageCell homePageCell];
}
cell.imageView.image = [UIImage imageNamed:#"XD"];
return cell;
}
These are the pictures. Top two are good, but when I slide down, as you can see, the 3rd doesn't work well
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HWHomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:#"HWHomePageCell"];
cell = [HWHomePageCell homePageCell];
cell.imageView.image = [UIImage imageNamed:#"XD"];
return cell;
}
When you use custom cell then no need to check whether cell is nil or not. so please remove this condition and implement it.
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
I have a problem when I setImageWithURL on an UIImageView into an UITableViewCell.
Here is the table view rendered. On the left before that I pressed on the UITableViewCell and on the right after that I pressed it.
Here is my tableView:cellForRowAtIndexPath method :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"AddFriendCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *user = self.result[indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:#"%# %#", user[#"firstname"], user[#"lastname"]];
if (user[#"picture"]) {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://jawbone.com/%#", user[#"picture"]]];
[cell.imageView setImageWithURL:url placeholderImage:cell.imageView.image];
}
return cell;
}
I just had a very similar problem last night. It happens because the UITableViewCell overrides the constraints on an imageview property, and for some reason has some unreliable functionality. I understand that this isn't exactly the most clear explanation as I did not ultimately figure out the exact source of the problem, but I was able to find a workaround.
The fix for me was to:
Create a custom UITableViewCell
Add a UIImageView (call the property something other than imageView) and title UILabel
Constrain/set the frame of the UIImageView
Hi I have one UItableView with images,title and description
When i run the app i can see the images are showing as large size but if i click that row then images become small(original size ).
May i know why this happening?
code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
offerCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.offerImage.layer.masksToBounds=YES;
cell.offerImage.layer.cornerRadius=9.0;
cell.backgroundColor=[UIColor clearColor];
if([offertitle count]>0){
// Configure the cell...
NSLog(#"%#",backupImage);
[cell.offerImage setImageWithURL:[NSURL URLWithString:[backupImage objectAtIndex:indexPath.row]]placeholderImage:[UIImage imageNamed:#"Placeholder.png"]]
;
cell.offerTitle.text=[offertitle objectAtIndex:indexPath.row];
cell.offerDetails.text=[offerDetails objectAtIndex:indexPath.row];
}
// cell.websiteImage.image=[imageArray objectAtIndex:indexPath.row];
return cell;
}
In UitableViewCell, the default image frame will be change based on setting UIImage. I means if you set tableview height as 50, so by default the Default Cell UIImageView height 50. so based on height imageview width will be change for displaying the image without blur.
so you have to take all images are at same size, or You have to create custom UIImageView in place of cell default UIImageview.
I am trying to add/remove cells to my grouped table dynamically during runtime. This is my first app that I have ever made, and while I have tried many other people's suggestions, I am still not getting it to work. Here is my code that I am using:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UILabel *lblName = (UILabel *)[cell viewWithTag:100];
[lblName setText:[intervalArray objectAtIndex:[indexPath row]]];
return cell;
You will need to update the array (will need to be an NSMutableArray) that is being used as the datasource for the UITableView. Then you can
[self.myTableView reloadData];
To reload the tableview
This is a good guide for dealing with updating TableView rows:
http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/ManageInsertDeleteRow/ManageInsertDeleteRow.html
I want to create more detailed table cells. An example I found is the reddit.com client AlienBlue. Each cell has an image, the title of the post, then below it four other pieces of text. How can I "layer" text in a table cell?
Hi you should subclass UITableViewCell for custom User interface of a cell in a table view.
Also look at: UITableViewDataSource and UITableViewDelegate for other options with regard to table view.
Probably your subclassed UiTableViewCell will have custom fields for title (UILabel), caption (UILabel) and for an image (UIImageView)
Examples:
Crafting Custom UITableView Cells
Customize Table View Cells For UITableView
You will want to create a custom UITableViewCell. It's quite trivial, and can be done either entirely in code (my favorite) or through IB.
Google custom UITableView cell for some great tutorials.
Use NSMutableArray of NSMUtableDictionary, as opposed to NSArray or NSMutableArray, to hold data (strings, images, ...).
Set the table cell style property to UITableViewCellStyleSubtitle so that the table can display the detailedTextLabel (cell.detailTextLabel.text).
You can set an image to the table cell.
Example
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
UIImage *image = [[list1 objectAtIndex:indexPath.row] objectForKey:key1a];
cell.imageView.image = image;
NSString *categoryname = [[list1 objectAtIndex:indexPath.row] objectForKey:key1b];
cell.textLabel.text = categoryname;
cell.detailTextLabel.text = [[list1 objectAtIndex:indexPath.row] objectForKey:key1e];
cell.detailTextLabel.textColor = [UIColor blueColor];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[NSString stringWithFormat:#"%#",[appdelegate.name objectAtIndex:indexPath.row]];
UIImage *image = [[array1 objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [[array1 objectAtIndex:indexPath.row];
return cell;
}