我已經創建了一個包含UITabBar屬性的特定列表的自定義單元格。這個單元格有其特定的類叫做RecomandationCell
,我已經聲明瞭這些屬性。從自定義UITableViewCell中委託製表符
我用這個自定義單元格來創建多個小區不同的對象,我也想知道,當我在一個特定的行點擊該標籤欄的項目稱之爲來自代表團的<UITabBarControllerDelegate>
這是
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (item.tag==0)
{
NSLog(@"Likes Clicked");
}
if (item.tag==1)
{
NSLog(@"Comments Clicked");
}
if (item.tag==2)
{
NSLog(@"Shares Clicked");
}
if (item.tag==3)
{
NSLog(@"Add Clicked");
}
if (item.tag==4)
{
NSLog(@"Ratings Clicked");
}
}
其方法
問題是,這種方法不會被解僱,因爲我不知道在哪裏委託它,甚至如果我委託它,我不知道在特定索引點擊了哪個標籤欄。
RecomandationCell.h
#import <UIKit/UIKit.h>
@interface RecomandationCell : UITableViewCell <UITabBarControllerDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *wineImage;
@property (weak, nonatomic) IBOutlet UITextView *wineName;
@property (weak, nonatomic) IBOutlet UILabel *wineYear;
@property (weak, nonatomic) IBOutlet UITabBar *socialTabBar;
@end
RecomandationCell.m
#import "RecomandationCell.h"
@implementation RecomandationCell
@synthesize socialTabBar;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (item.tag==0)
{
NSLog(@"Likes Clicked");
}
if (item.tag==1)
{
NSLog(@"Comments Clicked");
}
if (item.tag==2)
{
NSLog(@"Shares Clicked");
}
if (item.tag==3)
{
NSLog(@"Add Clicked");
}
if (item.tag==4)
{
NSLog(@"Ratings Clicked");
}
}
@end
RecomandationViewController.h
#import <UIKit/UIKit.h>
#import "RecomandationCell.h"
@interface RecomandationViewController : UIViewController <UITableViewDataSource,UITableViewDataSource,RecommandationCellDelegate>
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentView;
@property (weak, nonatomic) IBOutlet UITableView *winesTable;
@end
Recomandat ionViewController.m
#import "RecomandationViewController.h"
#import "RecomandationCell.h"
@interface RecomandationViewController()
@end
@implementation RecomandationViewController
{
NSMutableArray *rowArray;
//Titles for wine properties
NSMutableArray *wineNames;
NSMutableArray *wineProductors;
NSMutableArray *winePlaces;
NSMutableArray *wineYears;
NSMutableArray *wineRatings;
//Badges for Tab Bar items
NSMutableArray *nrOfRatings;
NSMutableArray *nrOfLikes;
NSMutableArray *nrOfComments;
NSMutableArray *nrOfShares;
NSMutableArray *addToWishLists;
}
@synthesize winesTable,segmentView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
rowArray = [[NSMutableArray alloc]initWithObjects:@"picture1.jpg",@"picture2.jpg",@"picture3.jpg",@"image4.jpeg",@"image5.jpeg",@"image6.jpeg", nil];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
// return rowArray.count;
return 6;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"mainCell";
RecomandationCell *cell = [self.winesTable dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.delegate = self;
cell.wineImage.contentMode = UIViewContentModeScaleAspectFill;
cell.wineImage.image = [UIImage imageNamed:[rowArray objectAtIndex:indexPath.row]];
[[cell.socialTabBar.items objectAtIndex:0]setBadgeValue:@"2"];
[[cell.socialTabBar.items objectAtIndex:1]setBadgeValue:@"3"];
[[cell.socialTabBar.items objectAtIndex:2]setBadgeValue:@"4"];
[[cell.socialTabBar.items objectAtIndex:4]setBadgeValue:@"19"];
cell.wineYear.text = @"2014";
cell.wineName.text = @"Alex\nMandi\nTirana\nOK";
return cell;
}
@end
任何建議,或者如果您需要更多的信息,請不要猶豫,評論
那你有沒有設置單元格的標籤欄的委託? – Wain
我已經設置了另一種方法的cell.delegate = self。 UITableViewCell的類沒有viewDidLoad,我不會在哪裏啓動它。 – EridB
告訴我你想要做什麼..應用程序流。 –