Is there a UIButtonCell like NSButtonCell in iOS - ios

If I want to make a 10X10 buttons in a view, the simple way is to make 100 buttons,
in Cocoa there is a NSButtonCellcan be used, so is there some thing like it in iOS?

your can create a custom cell
drag and drop a tableView cell and design with your buttons
and
add your custom tableView cell in cellForRowAtIndexPath like this,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *yourCustomeCelldentifier = #"CustomeTableCell";
yourCustomeCell *cell = (yourCustomeCell *)[tableView dequeueReusableCellWithIdentifier:yourCustomeCelldentifier];
if (cell == nil)
{
NSArray *nib;
nib = [[NSBundle mainBundle] loadNibNamed:#"CustomeCell_Nib" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
return cell;
}
hope this way will help you

Related

Custom cells of uitableview are not visible

Im using a tableview with custom cell.
My custom cell has got label and I have defined its outlet at 'StatutoryMappingCell.h'
Following isn cellForRowAtIndexPath method,
StatutoryMappingCell * cell = [tableView dequeueReusableCellWithIdentifier:#"myCell"];
if (!cell)
{
[tableView registerNib:[UINib nibWithNibName:#"KnowledgeMainCell" bundle:nil] forCellReuseIdentifier:#"myCell"];
cell = [tableView dequeueReusableCellWithIdentifier:#"myCell"];
}
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(StatutoryMappingCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.statMapping.text = [self.items objectAtIndex:indexPath.row];
}
The problem is that the cells are not visible when I run my code. But the Why is that so?
This is my xib scene...
This is my storyboard scene
Look in your interface builder - you shuld have not conntected your custom cell, you should set it as a files owner , if yes check once the labels are connected or not,
try these code
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"identifier";
CellItemList *cellA = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellA == nil)
{
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:(isIpad)?#"CellItemList~ipad":#"CellItemList" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cellA = (CellItemList *)[topLevelObjects objectAtIndex:0];
}
cellA.statMapping.text = [tableData objectAtIndex:indexPath.row];
return cellA;
}

UITableView: how implement only one row different from the others

in Storyboard (in Xcode 6) i want design a view like this
user profile view
The rows are dynamic because the content is get from a web services. How can i implement this view?
I have tried with an image view (the upper image with user name and pic) with a table view below but when i scroll the table obviously scroll only the table.
The image in the link is a uitableview with only the first row different from the other? How can implement only one row different from the other?
Thanks
That view could either be a tableHeaderView which does scroll with the table, or a cell. You can create as many prototype cells in the table view as you want, and give them different reuse identifiers. In cellForRowATIndexPath, put in an if-else clause, and dequeue whichever cell you want based on the indexPath.row.
Take two custom cells give different identifiers .one for only your first row and other for n-1 cells.
and load cellForRowATIndexPath as
before that take one temporary array
NSArray *arr=[[NSArra alloc]initWithObjects:#"FirstIdentifer",#"SecondIdientfier"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [self.menuItems objectAtIndex:indexPath.row];
if ([CellIdentifier isEqualToString:#"FirstIdentifer"]) {
Mycell *cell = (Mycell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"TempCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
//do your stuff
return cell;
}
else
{
static NSString *simpleTableIdentifier = #"SecondIdientfier";
cell1 = (Mycell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"Mycell" owner:self options:nil];
cell1 = [nib objectAtIndex:0];
//do your stuff
return cell1;
}
}

iOS keyboard with next, previous and done buttons, for text fields in UITableView

I have a UItableview with custom cells containing textfield.
In the table view I have 5 rows, with the custom cell.
I would like to implement the accessory view (Next, previous, Done buttons) for the text fields loaded in the tableview. Please help.
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"CPMyTableViewCell";
CPMyTableViewCell *cell = (CPMyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CPMyTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.textVw.placeholder = #"text";
return cell;
}
You can use BSKeyboardControls
https://github.com/SimonBS/BSKeyboardControls.
Through this it is very easy to add the controls to a keyboard. You can also find example in the project.
Also have a look at this

Getting EXC_Bad_Access while scrolling tableview

I am getting EXC_BadAccess error message while i am scrolling tableview.
the following is the code i have done in cellForRowAtIndexPath.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier=#"customCellHistory";
customCellHistory *cell=(customCellHistory*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects=[[NSBundle mainBundle]loadNibNamed:#"customCellHistory" owner:self options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]] ) {
cell=(customCellHistory*)currentObject;
break;
}
}
}
cell.lb11.text=[cellArray1 objectAtIndex:indexpath.row];
cell.lbl2.text=[cellArray2 objectAtIndex:indexpath.row];
return cell;
}
I can sense the problem is arising due to some mistake in the above code.
I used CustomCell in the above code to display a customized cell.
can anyone tell me what wrong have i done in this code
Hey try the following code, dont forget to set the cell identifier in you custom XIB to customCellHistory
At the top
#import "customeCellHistory.h"
then
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"customCellHistory";
customCellHistory *cell = (customCellHistory *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"customCellHistory" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.lb11.text=[cellArray1 objectAtIndex:indexpath.row];
cell.lbl2.text=[cellArray2 objectAtIndex:indexpath.row];
return cell;
}
The problem seems to arise from the strange loop you have. Use the last object method to set cell from the nib.
You are reusing a cell and then changing the cell in your loop which probably leads to a cell not existing where you are looking.
if (cell == nil) {
NSArray *topLevelObjects=[[NSBundle mainBundle]loadNibNamed:#"customCellHistory" owner:self options:nil];
You don't need that code. Just register the nib with the table view, earlier on:
[self.tableView registerNib:[UINib nibWithNibName:#"customCellHistory" bundle:nil]
forCellReuseIdentifier:#"customCellHistory"];
Now when you call dequeueReusableCellWithIdentifier, the nib will be loaded and the cell will be delivered, if there is no spare cell in the reuse pile. This ensures that you consistently have a cell and that it is the right kind of cell. Use the methods the framework gives you.

Second Cell appearing only after first cell is selected in Tableview ios

When I run my ios app, only the first cell displays in the TableView, then when clicked the second cell displays. I would like them both to display at the same time, but I cannot figure out this behavior.
Here is the code for my view did load
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"ProductCellId";
ProductTableCell *cell =
(ProductTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"ProductTableCell" owner:self options:nil];
cell = self.productCell;
}
Product *product = [products objectAtIndex:indexPath.row];
[cell configureForProduct:product];
return cell;
}
Any help would be much appreciated!
Since you are loading your cell from Interface builder try this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ProductTableCell"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"ProductTableCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
Product *product = [products objectAtIndex:indexPath.row];
[cell configureForProduct:product];
return cell;
}
Change this:
static NSString *CellIdentifier = #"ProductCellId";
to:
static NSString *CellIdentifier = #"ProductTableCell";
You can find additional information for what you are trying to do in this question: Load cells from XIB files

Resources