didSelectRowAtIndexPath Is Not Executing With Custom Cell tableView - objective-c

I have a tableView with custom cell and when i select a row nothing is happening?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrayOfExpectations count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"CustomCell"];
Expectations *expectation = [arrayOfExpectations objectAtIndex:indexPath.row];
cell.quoteLabel.text = expectation.expText;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// Calculate a height based on a cell
if(!self.customCell) {
self.customCell = [self.tableView dequeueReusableCellWithIdentifier:#"CustomCell"];
}
Expectations *expectation = [arrayOfExpectations objectAtIndex:indexPath.row];
self.customCell.quoteLabel.text = expectation.expText;
[self.customCell layoutIfNeeded];
// Get the height for the cell
CGFloat height = [self.customCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
// Padding of 1 point (cell separator)
CGFloat separatorHeight = 1;
return height + separatorHeight;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Expectations *expectation = [arrayOfExpectations objectAtIndex:indexPath.row];
expParentID = expectation.expID;
NSLog(#"PrevID = %#", prevexpParentID);
NSLog(#"NewID = %#", expParentID);
[self loadData];
}

Selecting option was blocked. Thank you viper king

Related

Content view does not show when testing in Objective-C

I am pretty new to Objective-C and I am stuck in this part. I am trying to display the controls the textfield, label, Gradient views, and the Transfer button which are inside the content view of the cell, but it does not appear when I test it out. It only shows "1. Data to operate" twice but no content.. Can someone please help me out with this? I would appreciate it.
Below is how my ViewController looks like:
#implementation CNCTransfersOwnViewController{
}
//#synthesize delegate;
+ (id)instanceFromStoryboard {
return [self instanceFromStoryboardNamed:#"Transfer"];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpUI];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)setUpUI {
self.navigationBar.topItem.title = #"GO TO SOMEWHERE ELSE";
}
- (NSString *)identifierForCellAtIndexPath:(NSIndexPath *)indexPath {
NSString *identifier = #"";
identifier = #"OPERATION";
return identifier;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(self.tableView == tableView){
return 2;
}else{
return 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(self.tableView == tableView){
NSString *identifier = [self identifierForCellAtIndexPath:indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
return nil;
}
You need to set the text you want to display in the cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(self.tableView == tableView){
NSString *identifier = [self identifierForCellAtIndexPath:indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = #"The text you want to display";
return cell;
}
return nil;
}

Insert CollectionView into TableView Cell in ios

I have a tableview which have 4 row. then i want to insert a collectionview into tableview cell and each collectionview have different cell. But i can't do that. can any one help me out or any suggesition?
You can give different CellIdentifiers for every TableViewCell and createa different rows in InterfaceBuilder or inside
cellForRowAtIndexPath
Dont forget to provide dataSource and delegate for every collectionView that you will create for TableViewCell
Pseudocode:
YN Means YourNamespace
YNDataSourceDelegate1* data1;
YNDataSourceDelegate2* data2;
YNDataSourceDelegate3* data3;
YNDataSourceDelegate4* data4;
const NSInteger COLLECTION_VIEW_TAG = 1001;
NSArray* providers=#[data1,data2,data3,data4];
NSArray* rowIds=#[#"row1",#"row2",#"row3",#"row4"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:rowIds[indexPath.row]];
UICollectionView * collectionView = (UICollectionView*)[cell viewWithTag:COLLECTION_VIEW_TAG];
collectionView.dataSource = providers[indexPath.row];
return cell;
}
This code will help you
yourViewController.h
#interface testingvc : UIViewController
<
UITableViewDelegate,
UITableViewDataSource,
UICollectionViewDelegate,
UICollectionViewDataSource
>
{
IBOutlet UITableView *tbleeView;
}
yourViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
tbleeView.delegate=self;
tbleeView.dataSource=self;
tbleeView.pagingEnabled=YES;
}
yourTableViewCell.h(UITableViewCell)
#property(strong,nonatomic)IBOutlet UICollectionView *clview;
yourViewController.m
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Incomplete implementation, return the number of sections
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete implementation, return the number of rows
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *identifierDriver = #"abcdefgh";
yourTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierDriver forIndexPath:indexPath];
//testing table cell is a UITableViewCell
if (cell == nil)
{
cell = [[testingTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierDriver];
}
cell.backgroundColor=[UIColor yellowColor];
//#property(strong,nonatomic)IBOutlet UICollectionView *clview;-this method is implement in UITableViewCell
// call collection view delegate method in table view cell.
cell.clview.delegate=self;
cell.clview.dataSource=self;
cell.clview.parentIndexpath = indexPath;
cell.clview.backgroundColor=[UIColor magentaColor];
cell.clview.pagingEnabled=YES;//optional
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSArray *collectionViewArray = [_arrayProducts [[(IndexedCollectionView *)collectionView parentIndexpath].row]objectForKey:#"inventory"];//arrProducts is an array where i get all the data from webservice
return [collectionViewArray count];
}
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point
{
return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
yourColloectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"abcdef" forIndexPath:indexPath];
NSArray *Products = [_arrayProducts[[(yourCollectionView *)collectionView parentIndexpath].row]objectForKey:#"inventory"];//arrProducts is an array where i get all the data from webservice
NSLog(#"object ibde xis ----%ld",[Products count]);
if (indexPath.row>[Products count]-1 )
{
NSLog(#"index not found");
}
else
{
NSDictionary *dictdata = [Products objectAtIndex:indexPath.row];
NSLog(#"dictdata is =====%#",dictdata);
//do your code here
}
if (indexPath.row % 2)
{
cell.backgroundColor=[UIColor brownColor];;
}
else
cell.backgroundColor=[UIColor redColor];;
return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (void)collectionView:(IndexedCollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger tableindex = collectionView.parentIndexpath.row;
NSLog(#"collection path row is ----%ld",tableindex);
NSLog(#"collection path row is ----%ld",indexPath.row);
//you can get all that index path number . Enjoy :)
}

change height of a specific custom uitableviewcell when touched

/*
i want to tap the uitableviewcell and its height should increase and than when i tap again on the same cell the size of cell should reduce. The size of custom cell is 293, but it should be 217 in start , when i touch it , it should be 293 and if i touch it again it should go back to 217. The same happens for all the cells. Please see the image links to have a better understanding.
- https://drive.google.com/file/d/0B6FUABgh-tDmZ3BteVhpWFU2d3M/view?usp=sharing
- https://drive.google.com/file/d/0B6FUABgh-tDmbklNRVhqT0lnbVE/view?usp=sharing
*/
- (void)viewDidLoad
{
[super viewDidLoad];
selectedrow = -1;
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.tableView registerNib:[UINib nibWithNibName:#"SelectedResturentCell" bundle:nil] forCellReuseIdentifier:#"SelectedResturentCell"];
NormalSize = 217;
ExpandedSize = 290;
[buyBtnTpd.layer setCornerRadius:2.0];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"SelectedResturentCell";
cell = (SelectedResturentCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.firstBtnOutlet addTarget:self action:#selector(cellBtnTpd) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int row = [indexPath row];
selectedrow = row;
//[tableView reloadData];
[tableView beginUpdates];
[tableView endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ( selectedrow == [indexPath row])
{
NSIndexPath *index = [tableView indexPathForCell:cell];
cellHeight = [self tableView:tableView heightForRowAtIndexPath:index];
if (cellHeight < ExpandedSize)
{
return ExpandedSize;
}
else
return NormalSize;
}
else return 217;
}

How do I add spacing between a UITableView cell image/label and the separator?

I have a UITableView with UIImage images populated in the cells. I want to be able to add some spacing between each image, and the separator lines because as you can see, some of the images are really close to the separator lines.
I could just modify the images and add spacing for each image, but I'd rather not.
Attached is what I like to achieve with the red arrows.
How can I achieve this?
Thanks.
Added code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [sponsorsLogoArray count];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView respondsToSelector:#selector(setSeparatorInset:)])
{
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:#selector(setLayoutMargins:)])
{
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setLayoutMargins:)])
{
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
- (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];
}
// Set cell background color to be transparent as it cannot be achieved via storyboard
cell.backgroundColor = [UIColor clearColor];
// Populate each cell with image from array
cell.imageView.image = [UIImage imageNamed:[sponsorsLogoArray objectAtIndex:indexPath.row]];
return cell;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
return indexPath;
}

cellForRowAtIndexPath called no. of times that array count return,Why?

I am facing new problem.In my app, i am getting data by using NSXmlParser.
After parsing data , i am creating UITableview manually.
Here is my code,
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
parser = [[NSXMLParser alloc]initWithData:self.cData];
parser.delegate = self ;
[parser parse];
tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, 320, 460) style:UITableViewStylePlain];
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
}
This is my delegates methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return eventName.count;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
-(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]autorelease];
}
for (int i=0; i < eventName.count; i++)
{
cell.textLabel.text = [eventName objectAtIndex:i];
NSLog(#"%#",cell.textLabel.text);
}
return cell;
}
Instead of checking i in the for loop, remove the for loop and look for indexPath.row in-
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
cell.textLabel.text = [eventName objectAtIndex:indexPath.row];
...
}
It will be called as many times as the value returned by-
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{}