How to show disclosure indicator while cells are in edit mode? - iphone

I have a UITableView that can be edited. I am displaying cells as such:
- (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];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell...
STWatchList *mySTWatchList;
mySTWatchList = [items objectAtIndex:indexPath.row];
cell.textLabel.text = mySTWatchList.watchListName;
return cell;
}
When the user is editing, I would like to show the disclosure indicator. How can I accomplish this?

cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;

if (indexPath.row==0)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

Related

Error [IRForTarget] in UITableView

I am having more than a table view in a view controller, it is giving error. I have no idea what is where going wrong can anyone guide. Data is not showing in table view but array has data when printed in console, i tried without array also providng static data to cell.textLabel.text, but not showing in tableview, numbers of rows checked no issue there. control does not go to cell.textLabel.text, i am not getting what is wrong. Please guide for the above. Below is the code:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell;
if(tableView == self.mLocationTable)
{
cell = [self.mLocationTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
else{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// if([self.mLocShowArr count]!= 0)
// {
// NSString *str = [self.mLocShowArr objectAtIndex:indexPath.row];
cell.textLabel.text = #"locations";
// NSLog(#"show loc:%#", [self.mLocShowArr objectAtIndex:0]);
// }
}
if(tableView == self.mNotifyTable)
{
cell = [self.mNotifyTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UIImage *yourImage = [UIImage imageNamed:#"emma-watson-02.jpg"];
UIImageView *imageViewToPutInCell = [[UIImageView alloc] initWithImage:yourImage];
imageViewToPutInCell.frame = CGRectMake(5, 8, 55, 55);
UILabel *cellTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(68, 10, 200, 40)];
cellTextLabel.text = #"notification view";
[cell addSubview:imageViewToPutInCell];
[cell addSubview:cellTextLabel];
}
}
This is the complete error : Error [IRForTarget]: Call to a symbol-only function 'objc_msgSend' that is not present in the target.
Things to check.
Data source methods all required implemented
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
log the return value and make sure it is not 0
Give the different cell identifier for different tables
Make sure table data source and delegates are connected in the nib
Error Explanation here
Try this code !!! In your code you missed "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:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.accessoryType = UITableViewCellAccessoryNone;
}
if(tableView == self.mNotifyTable) {
cell.textLabel.text = #"locations";
UIImage *yourImage = [UIImage imageNamed:#"emma-watson-02.jpg"];
UIImageView *imageViewToPutInCell = [[UIImageView alloc] initWithImage:yourImage];
imageViewToPutInCell.frame = CGRectMake(5, 8, 55, 55);
UILabel *cellTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(68, 10, 200, 40)];
cellTextLabel.text = #"notification view";
[cell addSubview:imageViewToPutInCell];
[cell addSubview:cellTextLabel];
}
return cell;
}
Hope this solves your problem !!!
Accept the answer if it helps you !!!

cell.detaillabel's text not shown

I have a tableView in which I need to show textlabel and detailtextlabel.
But detailtextlabel is not shown.
-(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];
}
NSMutableDictionary *d2 =[[NSMutableDictionary alloc]initWithDictionary:[autocompleteUrls objectAtIndex:indexPath.row]];
cell.textLabel.text = [NSString stringWithFormat:#"%#",[d2 valueForKey:#"FLName"]];
cell.detailTextLabel.text=#"Id";
cell.textLabel.font=[UIFont boldSystemFontOfSize:12];
cell.textLabel.numberOfLines=0;
return cell;
}
But detailtextlabel is not shown, why?
You use UITableViewCellStyleDefault but you have to use UITableViewCellStyleSubtitle
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];
I usually use UITableViewCellStyleValue1 in this case
[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]
To give you answer in details :

how can add a label to every row in tableview in iphone

I want add label to every row in tableview at right side of the row in iphone programmatically.
Can anyone help me?
-(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] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
UILabel* lbl = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
lbl.font = [UIFont boldSystemFontOfSize:17.0];
lbl.text = [self.arrRows objectAtIndex:indexPath.row];
[cell.contentView addSubview:lbl];
[lbl release];
return cell;
You can achieve it like this :
- (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];
}
UILabel *lblText = [[UILabel alloc] initWithFrame:CGRectMake(200, 3, 100, 15)]; // For right alignment
lblText.text = [self.arrText objectAtIndex:indexPath.row];
lblText.textColor = [UIColor blackColor];
[cell addSubview:lblText];
[lblText release];
return cell;
}
I think you are asking for code.
try
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UILabel *yourLabel = nil;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
yourLabel = [[UILabel alloc] initWithFrame:CGRect……];
[yourLabel setTag:9999];
[[cell contentView] addSubview:addressLabel];
}
if (!yourLabel)
yourLabel = (UILabel*)[cell viewWithTag:9999];
return cell;
}
In your cellForRowAtIndexPath: method :-
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=#"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//set reuseIdentifier:nil for avoid label overlapping
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
//make your label as according to you
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
label.backgroundColor = [UIColor redColor];
// add label content view of cell
[cell.contentView addSubview:label];
return cell;
}

Last row in UITableview copying to other rows

I have a UITableView that is grouped into sections and has a number of rows in each section, all the rows are disabled so they only show information and they do not allow user interaction except for the very last row. But when the user scrolls through the table the last row is getting copied to some of the other rows in the table. Here is my code.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
cell.accessoryType = UITableViewCellAccessoryNone;
UIFont *textLabelFont = [ UIFont fontWithName: #"Arial" size: 13.0 ];
UIFont *detailLabelFont = [UIFont fontWithName:#"Arial" size:13.0];
cell.textLabel.font = textLabelFont;
cell.detailTextLabel.font = detailLabelFont;
// Configure the cell.
[populatePolicyCells ProcessPolicyCell:cell IndexPath:indexPath];
if (indexPath.section == 3){
tableView.allowsSelection = YES;
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.userInteractionEnabled = YES;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.textLabel.text = #"Manage Policy";
}
return cell;
}
Can anyone help?
Set up a different CellIdentifier for your "special cell"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell* cell = nil;
if (indexPath.section == 3)
{
cell = [tableView dequeueReusableCellWithIdentifier:#"SpecialCell"];
if(cell == nil)
{
tableView.allowsSelection = YES;
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:"SpecialCell"] autorelease];
cell.userInteractionEnabled = YES;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
cell.textLabel.text = #"Manage Policy";
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
cell.accessoryType = UITableViewCellAccessoryNone;
UIFont *textLabelFont = [ UIFont fontWithName: #"Arial" size: 13.0 ];
UIFont *detailLabelFont = [UIFont fontWithName:#"Arial" size:13.0];
cell.textLabel.font = textLabelFont;
cell.detailTextLabel.font = detailLabelFont;
}
// Configure the cell.
[populatePolicyCells ProcessPolicyCell:cell IndexPath:indexPath];
}
return cell;
}
change the dequeueCellWithIdentifier , everytime you reuse the tableview

UITableView add control issue in iphone

I am adding an activity indicator in each row of table. The issue is every time I scroll it get added again in cell overwriting the previous one. Please let me know which is best way to add control in tableview cell.
UIActivityIndicatorView *a;
// Customize the appearance of table view cells.
-(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];
}
a = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[a startAnimating];
[cell.contentView addSubview:a];
// Configure the cell.
return cell;
}
Add indicator to a cell only when you create it, then you can access it using its tag property:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
a = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
a.tag = 10;
[cell.contentView addSubview:a];
}
UIActivityIndicatorView* aView = [cell.contentView viewWithTag:10];
[aView startAnimating];