2015-01-09 3 views
1

내 TableView 앱용 사용자 정의 셀이 있습니다. TableViewController는 "BlogView"라고합니다. 내 사용자 정의 셀에는 몇 개의 버튼이 있습니다. 하나는 공유 버튼입니다. 단추 중 하나가 눌려지면 UIActivityViewController를 표시하려고합니다. 내 사용자 지정 셀의 헤더에 사용자 정의 셀에서 ActivityViewController 호출

, 나는 속성이 있습니다 사용자 정의 셀에

@property (nonatomic, retain) BlogView *myViewController; 

을, 나는 layoutSubview 위해 가지고 : 내가 가지고있는 선택 didTapCommentButtonAction를 들어

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

:

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

    } 

블로그보기

- (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; 
} 

경고 나 오류는 표시되지 않지만 버튼을 클릭해도 아무런 변화가 없습니다.

+0

다른 코드가 있습니까? 난 당신이 사용자 정의 셀 클래스 내부에 귀하의 버튼에 대한 속성이 필요하다고 생각해. 그런 다음 해당 속성 단추에 선택기를 추가 할 수 있습니다. 선택기 메서드 내에서 ActivityViewController를 시작할 수 있습니다. –

+0

presentViewController는 버튼이 호출하는 선택기 메서드 안에 있습니다. @JoshEngelsma – user717452

+0

myViewController 란 무엇이며, avc는 무엇입니까? 그 중 하나에 대한 참조를 만들거나 참조를 얻습니까? – rdelmar

답변

2

1 단계 :는 CustomCell.h 파일 휴대의 버튼에서 함께 IBOutlet을 얻을 ...

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

2 단계 : 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]; 

3 단계 :은 CustomCell.m 대신 BlogView.m 파일 내부에서 선택기 메서드를 구현합니다.

+0

그것은 그것을했다. 나는 아직도 커스텀 셀에 익숙하지 않아서 버튼을 씌우고있어, 그렇게 말하면서 나를 괴롭혔다.나는 3 시간 동안 유사한 문제를 찾기 위해 인터넷 검색을했고, 가장 가까운 곳에서 참조 부모 컨트롤러라고 말한 사람이 있었는데, 다른 텍스트가없는 것으로 받아 들여진 것으로 표시되었다. – user717452

+0

굉장한 사람! 다행 다행! 너의 실수가 뭔지 이해하니? 기본적으로보기의 단추가 UIButton 속성에 연결되었다고 생각하고 있었지만 처음에는 IBOutlet을 설정하지 않은 채로있었습니다. –

+0

예, 36 시간 동안 코딩이 거의 완료되어 약간 퍼지기 시작했습니다. – user717452

관련 문제