我知道几次有关如何向tableviewcell添加徽章的类似问题,但我无法使其正常工作
基本上我想要的是向用户显示简单的通知,无论是表格视图单元格右侧的红色数字,还是矩形或类似的本机电子邮件应用程序。
所以我尝试了这两个源代码TDbadgcell和DDbadgecell
现在问题是我不能委托他们,我必须导入他们的.h类并在我的表视图中调用以下任一函数
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TDBadgedCell *cell = [[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
或
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
DDBadgeViewCell *cell = (DDBadgeViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[DDBadgeViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
但是当我这样做时,我的tableView didSelectRowAtIndexPath:
和(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
方法无法正常工作,我可以点击行但是它们保持高亮蓝色也没有任何反应,我的桌子右侧的箭头也会消失。
那么如何使用上述源代码或任何其他方法为表格视图单元格行添加徽章?
EDIT ::: 在放入NSLOG之后我可以看到选择行被调用但是执行segue仍然不起作用。如果不添加任何上述代码,它就会完美无缺。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//static NSString *CellIdentifier = @"MeetingCell";
static NSString *CellIdentifier = @"Cell";
DDBadgeViewCell *cell = (DDBadgeViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[DDBadgeViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *description =@":";
NSString *name =@"";
NSString *fileStatus=@"";
name = [[self agenda] getFileNameWithSection:[indexPath section] Row:[indexPath row]];
description = [[self agenda] getFileDescriptionWithSection:[indexPath section] Row:[indexPath row]];
fileStatus = [[self agenda] getFileStatusWithFileName:name];
NSString * cellLabel = [NSString stringWithFormat:@" %@ : %@",description,name];
//alloc row images
UIImage *docImage = [UIImage imageNamed:@"ICON - Word@2x.png"];
UIImage *xlsImage = [UIImage imageNamed:@"ICON - Excel@2x.png"];
// UIImage *picImage = [UIImage imageNamed:@"ICON - Image@2x.png"];
UIImage *pdfImage = [UIImage imageNamed:@"pdf icon@2x copy.png"];
UIImage *pptImage = [UIImage imageNamed:@"ICON - PPT@2x.png"];
//Determine what status to display for a file
//No need to that since wee use push notification
if ([fileStatus isEqualToString:@"new"]){
cellLabel = [NSString stringWithFormat:@"%@ (%@)",cellLabel,@"New"];
cell.badgeText = [NSString stringWithFormat:@"Update"];
cell.badgeColor = [UIColor orangeColor];
}else if ([fileStatus isEqualToString:@"outdated"]){
cellLabel = [NSString stringWithFormat:@"%@ (%@)",cellLabel,@"Outdated"];
cell.badgeText = [NSString stringWithFormat:@"Update"];
cell.badgeColor = [UIColor orangeColor];
}else if ([fileStatus isEqualToString:@"updated"]){
cellLabel = [NSString stringWithFormat:@"%@ (%@)",cellLabel,@"Latest"];
}
UIFont *font1 = [UIFont fontWithName:@"Century Gothic" size:15.0f];
cell.textLabel.font=font1;
//if there is no file user can not tocuh the row
if ([name length]==0) {
cell.userInteractionEnabled = NO;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.textLabel.text = description;
}else{
//set cell title
cell.textLabel.text = cellLabel;
}
//set row images
if ([name rangeOfString:@"docx"].location != NSNotFound) {
cell.imageView.image= docImage;
}else if ([name rangeOfString:@"xlsx"].location != NSNotFound){
cell.imageView.image= xlsImage;
}
else if ([name rangeOfString:@"pdf"].location != NSNotFound){
cell.imageView.image= pdfImage;
}
else if ([name rangeOfString:@"ppt"].location != NSNotFound){
cell.imageView.image= pptImage;
}
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"rounded corner box center@2x.png"]];
// At end of function, right before return cell
cell.textLabel.backgroundColor = [UIColor clearColor];
NSLog(@"%@",cell.textLabel.text);
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];.0
*/
NSLog(@"didselect row is called %d",indexPath.row);
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[DBSession sharedSession] isLinked]) {
if([[segue identifier] isEqualToString:@"pushDocumentView"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSInteger section =[indexPath section];
NSInteger row = [indexPath row];
NSString *fileName = [[self agenda] getFileNameWithSection:section Row:row];
NSDictionary * agendaDic = [[[self agenda]revision] objectForKey:fileName];
NSString *fileStatus =[agendaDic objectForKey:@"status"];
DocumentViewController *docViewController = [segue destinationViewController];
//This will display on the Document Viewer
docViewController.fileName=fileName;
//This will determine remote or local copy display
docViewController.fileStatus=fileStatus;
}
}else {
[self displayError];
[self setWorking:NO];
}
}
答案 0 :(得分:0)
刚刚用标识符调用了perfromsegue
因为当您拨打- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
[self performSegueWithIdentifier:@"yoursegue" sender:self];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];.0
*/
[self performSegueWithIdentifier:@"yoursegue" sender:self];
NSLog(@"didselect row is called %d",indexPath.row);
}