I have a table view and I set all of the odd cell height = 0, In odd cell I had some labels. When it show up the table view, the label in odd cell appear in the even cell. Is there any way to make the label vanish? This problem happened in ios 6
p/s:
in ios 7: it work right.
i already had the method : [tableView beginUpdates]; [tableView endUpdates];
Thanks.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
// show odd row
if (selectedRow == indexPath.row) return 78;
// hide odd row and show even row
if (indexPath.row %2 ==0){
return 88;}
else{
return 0;}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row%2 == 0){
//user click on even row -> display the next row
selectedRow = indexPath.row+1;
[tableView beginUpdates];
[tableView endUpdates];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int index = indexPath.row / 2;
if (indexPath.row %2 ==0){
static NSString *CellIdentifier = #"PhraseViewCell";
PhraseCellVietnamese *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *phrase = [[phrases objectAtIndex:index] objectForKey:#"vietnamese"];
NSNumber *checkFavorite = [[phrases objectAtIndex:index] objectForKey:#"favorite"];
NSNumber *phraseId =[[phrases objectAtIndex:index] objectForKey:#"_id"];
[cell SetInfo:phrase :checkFavorite.intValue :phraseId.intValue];
return cell;
}
else{
static NSString *CellIdentifier = #"PinyinViewCell";
PinYinViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *pinyin = [[phrases objectAtIndex:index] objectForKey:#"pinyin"];
NSString *chinese = [[phrases objectAtIndex:index] objectForKey:#"chinese"];
NSString *voice = [[phrases objectAtIndex:index] objectForKey:#"voice"];
[cell setInfo:pinyin :chinese :voice];
return cell;
}
}
[cell setClipsToBounds:YES]; in cellForRowAtIndexPath
worked for me. Hope you found your solution.
After reading user2799736 answer I changed
Clip Subviews
to YES in .xib file.
Worked for me.
Related
I am posting the code which I tried.I am getting string value and then I am adding it to an array and getting the array value too.But problem comes when I try to use the array value in other method ,it's value is blank.
//ViewController.h
#interface ViewController : UIViewController{
NSString *stringValueVideoiD;
NSMutableArray *TableVideoIDArray;
}
//ViewController.m
#implementation ViewController
- (void)viewDidLoad
{
TableVideoIDArray=[[NSMutableArray alloc]init];
[self getAllRows];
}
-(void) getAllRows{
if(sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK)
{
NSString *sqlStatement = [NSString stringWithFormat:#"SELECT * FROM table"];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(db,[sqlStatement UTF8String] , -1, &compiledStatement, NULL)== SQLITE_OK)
{
while(sqlite3_step(compiledStatement)==SQLITE_ROW)
{
char *videoId = (char *) sqlite3_column_text(compiledStatement, 1);
stringValueVideoiD = [[NSString alloc] initWithUTF8String:videoId];
TableVideoIDArray=[[NSMutableArray alloc]init];
[TableVideoIDArray addObject:stringValueVideoiD];
NSLog(#"vids array:%#",TableVideoIDArray);
//vids aray:value is printed
}
}
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell==nil) {
cell=[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSLog(#"here:%#",TableVideoIDArray);
//here comes the problem.My console result is
2013-09-18
11:18:24.431 TubeAlert[468:11303] here:(
)
//so guys I need your help why this is happenning or I am making mistakes in my code.
TableVideoIDArray allocated two times.
In viewDidLoad, use
TableVideoIDArray=[NSMutableArray array];
don't allocate with in a While loop.
I have a UITable, and I like to add an image in the detail view for a cell. I can handle the selection for any image from the camera roll or from the camera:
cell.imageView.image = someImage;
But how do I define a specific image - in the case above: "someImage", so that the next time the app is run, the correct image is shown for each item.
UPDATE. This is the code I'm using to snap/select an image..
- (IBAction)btnTakePicture_Clicked:(id)sender
{
NSLog(#"%s", __FUNCTION__);
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image from..." delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Camera", #"Image Gallary", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.alpha=0.90;
actionSheet.tag = 1;
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(#"%s", __FUNCTION__);
switch (actionSheet.tag)
{
case 1:
switch (buttonIndex)
{
case 0:
{
#if TARGET_IPHONE_SIMULATOR
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Ooops" message:#"Camera not available." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
#elif TARGET_OS_IPHONE
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
//picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:nil];
#endif
}
break;
case 1:
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
break;
}
break;
default:
break;
}
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
NSLog(#"%s", __FUNCTION__);
dataImage = UIImageJPEGRepresentation([info objectForKey:#"UIImagePickerControllerOriginalImage"],1);
imgPicture.image = [[UIImage alloc] initWithData:dataImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}
UPDATE 2. With the help from people below, I think this solution will work for me:
- (IBAction)photoLibraryAction:(id)sender
{
int c = self.capturedImages.count;
for (int i=0; i < c; i++ ){
if (self.imageView.tag == cellTag) {
NSLog(#"found it");
} else {
NSLog(#"can't find it");
}
}
}
if ([self.capturedImages count] == 1)
{
// we took a single shot
[self.imageView setImage:[self.capturedImages objectAtIndex:0]];
[self.imageView setTag:myTag];
}
I would do in this way.
#interface CustomClassCell : UITableViewCell
#property (unsafe_unretained, nonatomic) IBOutlet UIImageView *HomePicture;
#end
#interface CustomClass : NSObject
#property (nonatomic, copy) NSString *PicPath;
#end
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomClassCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CustomClassCellIdentifer"];
id object = [self.tableData objectAtIndex:indexPath.row];
CustomClass *myObject = (CustomClass*)object;
cell.HomePicture.image = [UIImage imageNamed:myObject.PicPath];
return cell;
}
I have mainView with an image displayed (Using Storyboards and imageViews and CollectionViews) when I select an cell from my CollectionView (in a popOver).
How do I create another (popover containing a UiCollectionView) that let's me select an image and place that second image on top of the one I already have displayed?
#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
// Return the number of sections.
// return [_carImages count] / 2;
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_carImages count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// CellTasteCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
// image = [[UIImage imageNamed:[_carImages objectAtIndex:indexPath.row]];
// cell.imageView.image = image;
// return cell;
NSLog(#"INDEX PATH roe %#",[_carImages objectAtIndex:indexPath.row]);
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
/*
UIImageView *brickAnim = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile: imageFilePath]];
brickAnim.frame = CGRectMake(0, 0, 62, 57);
[cell.contentView addSubview:brickAnim];
cell.layer.borderColor=[UIColor whiteColor].CGColor;
cell.layer.borderWidth=2.0;
*/ cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[_carImages objectAtIndex:indexPath.row]]];
return cell;
/* MyCollectionViewCell *myCell = [collectionView
dequeueReusableCellWithReuseIdentifier:#"MyCell"
forIndexPath:indexPath];
UIImage *image;
int row = [indexPath row];
image = [UIImage imageNamed:_carImages[row]];
myCell.imageView.image = image;
return myCell;*/
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
// UIImage *image =[UIImage imageNamed: [_carImages objectAtIndex:indexPath.row]];
return CGSizeMake(40, 40);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(20, 20, 20, 20);
}
#pragma mark -
#pragma mark UICollectionViewFlowLayoutDelegate
/*-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *image;
int row = [indexPath row];
image = [UIImage imageNamed:_carImages[row]];
return image.size;
}*/
- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition{
}
I am working with IOS 6 UITableView and my problem is that whenever i put the table view into edit mode, the edit control that appears next to the table view cell of deletestyle ( UITableViewCellEditingStyleDelete ) overlaps two labels ( xyzname and xyzcollege ).
I did not have this problem in IOS 5 (with same code).
CODE:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle]pathForResource:#"friends"ofType:#"plist"];
NSDictionary *xyz = [[NSDictionary alloc]initWithContentsOfFile:path];
_names = [xyz objectForKey:#"name"];
_colls = [xyz objectForKey:#"college"];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
NSInteger count =_names.count;
if(self.editing)
{
count++;
}
return count;
}
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
saumyaTableViewCell *cell;
cell = [_saumyaTable dequeueReusableCellWithIdentifier:#"saumyacell"];
if(indexPath.row < _names.count)
{
cell.xyzname.text = [_names objectAtIndex:indexPath.row];
cell.xyzcollege.text = [_colls objectAtIndex:indexPath.row];
}
else
{
cell.xyzname.text = #"Add name.";
cell.xyzcollege.text = #"Add College";
cell.editingAccessoryType =
UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
-(void)setEditing:(BOOL)editing animated:(BOOL) animated
{
if( editing != self.editing )
{
[super setEditing:editing animated:animated];
[_saumyaTable setEditing:editing animated:animated];
NSArray *indexes = [NSArray arrayWithObject:
[NSIndexPath indexPathForRow:_names.count inSection:0]];
if (editing == YES )
{
[_saumyaTable insertRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationLeft];
}
else
{
[_saumyaTable deleteRowsAtIndexPaths:indexes
withRowAnimation:UITableViewRowAnimationLeft];
}
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row < _names.count)
{
return UITableViewCellEditingStyleDelete;
}
else
{
return UITableViewCellEditingStyleInsert;
}
}
IMAGE DESCRIPTION:
1.UITableViewCell has two labels(xyzname and xyzcollege)
2.UITableViewCellEditingStyleDelete overlaps these two labels when cell goes into edit mode
What is to be done if i want those labels to automatically animate on the right side when my view goes into the edit mode and again animate to their original positions after coming out of the edit mode?
THANK YOU
Never called when a search table cell is tapped
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Show Detail"])
{
Player *player = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]];
[segue.destinationViewController setPlayer:player];
}
}
This filters the list correctly, but the prepareForSegue is never called when a search table cell is tapped.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Player Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.tableView)
{
// normal table view population
Player *player = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[NSString alloc] initWithFormat:#"#%# %# %#", player.number, player.firstName, player.lastName];
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:#"%#", player.position];
[cell.imageView setImageWithURL:[NSURL URLWithString:player.photo] placeholderImage:[UIImage imageNamed:#"playerplaceholder.jpg"]];
}
else if(tableView == self.searchDisplayController.searchResultsTableView)
{
// search view population
Player *player = [self.filteredFetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[NSString alloc] initWithFormat:#"#%# %# %#", player.number, player.firstName, player.lastName];
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:#"%#", player.position];
[cell.imageView setImageWithURL:[NSURL URLWithString:player.photo] placeholderImage:[UIImage imageNamed:#"playerplaceholder.jpg"]];
}
return cell;
}
you need to put IF that check if the search have results.
like in this code:
if ([[segue identifier]isEqualToString:#"ShowDetails"])
{
ShowDetailsViewController *sdvc = (ShowDetailsViewController *)[segue destinationViewController];
NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow];
Books *selectedBooks = nil;
if(self.searchDisplayController.active)
selectedBooks = (Books *)[[self searchResults]objectAtIndex:[[[[self searchDisplayController]searchResultsTableView]indexPathForSelectedRow]row]];
else
selectedBooks = (Books *)[[self fetchResultsController] objectAtIndexPath:indexPath];
sdvc.currentBooks = selectedBooks;
}