我有我的TableView應用程序的自定義單元格。 TableViewController被稱爲「BlogView」。我的自定義單元格上有幾個按鈕,其中一個是共享按鈕。我想在按下其中一個按鈕時呈現UIActivityViewController。從自定義單元調用ActivityViewController
在我的自定義單元格的頭,我有一個屬性:
@property (nonatomic, retain) BlogView *myViewController;
在自定義單元格,我有layoutSubview:
self.commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.commentButton addTarget:self action:@selector(didTapCommentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.commentButton setTitle:@"Share" forState:UIControlStateNormal];
[self.commentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.commentButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
對於選擇didTapCommentButtonAction我:
- (void)didTapCommentButtonAction:(id)sender
{
NSLog(@"CommentButtonTAPPED");
Mail *mail = [[Mail alloc]init];
NSString *html = self.prayerObject[@"Request"];
NSString *thetitle = [self.prayerObject[@"Title"] stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *thedate = self.prayerObject[@"dateMade"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMM_dd_yyyy"];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
NSDate *theNewDate1 = [dateFormat dateFromString:thedate];
NSString *theNewDate = [dateFormat stringFromDate:theNewDate1];
mail.thehtml = html;
self.nameofhtmlfile = [[[[@"http://www.iprayed4u.net/app/" stringByAppendingString:thetitle] stringByAppendingString:@"_"] stringByAppendingString:theNewDate] stringByAppendingString:@".html"];
// Reminder *thereminder = [[Reminder alloc] init];
//thereminder.thehtml = html;
//thereminder.thetitle = thetitle;
//thereminder.thedate = thedate;
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[self] applicationActivities:@[mail]];
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
activityVC.excludedActivityTypes = @[ UIActivityTypePostToWeibo,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeMail,
UIActivityTypePrint
];
}
else {
activityVC.excludedActivityTypes = @[ UIActivityTypePostToWeibo,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeMail,
UIActivityTypePrint,
UIActivityTypeAirDrop
];
}
NSLog(@"Test");
[self.myViewController presentViewController: activityVC animated: YES completion: nil];
}
In BlogView.m
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object
{
static NSString *CellIdentifier = @"Cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
self.theObject = object;
// Configure the cell to show todo item with a priority at the bottom
cell.profileName.text = object[@"Title"];
cell.contentLabel.text = object[@"Request"];
cell.firstName = object[@"FirstName"];
cell.lastName = object[@"LastName"];
cell.iostoken = object[@"DeviceID"];
cell.request = object[@"Title"];
cell.prayerObject = object;
PFFile *thumbnail = object[@"ProfilePic"];
cell.profilePic.image = [UIImage imageNamed:@"[email protected]"];
[thumbnail getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
UIImage *thumbnailImage = [UIImage imageWithData:imageData];
UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:thumbnailImage];
cell.profilePic.image = thumbnailImage;
}];
NSString *dates = object[@"dateMade"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM_dd_yyyy"];
NSDate *datefromstring = [formatter dateFromString:dates];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:@"MMM dd, yyyy"];
cell.dateLabel.text = [formatter2 stringFromDate:datefromstring];
UIFont *cellFont = [UIFont fontWithName:@"Verdana-Bold" size:15];
UIFont *cellFont2 = [UIFont fontWithName:@"Verdana-Bold" size:12];
return cell;
}
我沒有收到任何警告或錯誤,但是當我點擊按鈕時,沒有任何反應。
你有沒有其他的代碼?我認爲你需要在自定義單元類中使用你的按鈕屬性。那麼也許你可以添加一個選擇器到該屬性按鈕。在選擇器方法內部,您可以啓動ActivityViewController – 2015-01-09 22:23:20
presentViewController位於按鈕調用的選擇器方法內,@JoshEngelsma – user717452 2015-01-09 22:25:13
什麼是myViewController,什麼是avc?你是否創建或獲得了這兩個參考? – rdelmar 2015-01-09 22:25:20