gpt4 book ai didi

ios - 从自定义单元格调用 ActivityViewController

转载 作者:行者123 更新时间:2023-11-29 10:34:22 25 4
gpt4 key购买 nike

我的 TableView 应用程序有一个自定义单元格。 TableViewController 称为“BlogView”。我的自定义单元格上有几个按钮,其中一个是共享按钮。我想在按下其中一个按钮时显示一个 UIActivityViewController。

在我的自定义单元格的标题中,我有一个属性:

@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];

}

在 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:@"AppIcon60x60@2x.png"];
[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;
}

我没有收到任何警告或错误,但是当我点击按钮时,没有任何反应。

最佳答案

第一步:从单元格上的按钮获取 IBOutlet 到 CustomCell.h 文件...

@property (weak, nonatomic) IBOutlet UIButton *commentButton;

第二步:在 cellForRowAtIndexPath 中,为每个单元格上的按钮添加一个选择器,并根据需要对其进行修饰...注意我们正在添加选择器现在每个“单元格按钮”...不是 self.commentButton

[cell.commentButton addTarget:self action:@selector(didTapCommentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.commentButton setTitle:@"Share" forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];

第三步:在 BlogView.m 文件中而不是在 CustomCell.m 中实现选择器方法

关于ios - 从自定义单元格调用 ActivityViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27870078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com