tableviewcellにバッジを追加する方法について同様の質問が何度か寄せられていることは知っていますが、機能させることができませんでした
基本的に私が望むのは、テーブルビューセルの右側にある赤い数字または長方形またはネイティブの電子メールアプリのような簡単な通知をユーザーに表示することです。
だから私はこの2つのソースコード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
が機能しない場合、行をクリックすることはできますが、行は青くハイライトされたままになり、何も起こらず、テーブルの右側にある矢印が消えます。
上記のソースコードまたは他の方法で、テーブルビューのセル行にバッジを追加するにはどうすればよいですか?
編集::: NSLOG を配置した後、選択行が呼び出されたことがわかりますが、セグエの実行はまだ機能しません。上記のコードを追加しなくても、完全に機能します。
- (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];
}
}