15

Tôi đang sử dụng ShareKit 0.2.1 trên Xcode 4.2 (iOS SDK 5) để chia sẻ văn bản trên Twitter. Nó có tốt, nhưng bộ điều khiển xem phương thức sẽ không biến mất sau khi thành công chia sẻ trên sau khi nhấp vào nút Cancel (xem dưới đây):Bộ điều khiển chế độ xem ShareKit sẽ không biến mất

enter image description here

Và đây là mã của tôi:

-(IBAction)shareOnTwitter:(id)sender{ 


    // Item to share 
    NSString *text = @"Go away, modal view controller!"; 

    [SHKTwitter shareText:text]; 

} 

gì tôi đang làm sai à?

Trả lời

30

Tôi gặp vấn đề tương tự như bạn. Đây là một vấn đề iOS 5. Đó là vì ShareKit đang sử dụng phương thức trên UIViewController được gọi là parentViewController và theo tài liệu của Apple, bạn không thể sử dụng phương thức này trong iOS 5. Thay vào đó, bạn phải sử dụng presentingViewController.

Vì vậy, để khắc phục nó trong mã ShareKit, đi vào SHK.m, tìm ra phương pháp có chữ ký (void)hideCurrentViewControllerAnimated:(BOOL)animated, và thay thế bằng:

- (void)hideCurrentViewControllerAnimated:(BOOL)animated 
{ 
    if (isDismissingView) 
     return; 

    if (currentView != nil) 
    { 
     // Dismiss the modal view 
     if ([currentView parentViewController] != nil) 
     { 
      self.isDismissingView = YES; 
      [[currentView parentViewController] dismissModalViewControllerAnimated:animated]; 
     } else if ([currentView presentingViewController] != nil) { 
      self.isDismissingView = YES; 
      [[currentView presentingViewController] dismissModalViewControllerAnimated:animated]; 
    } else 
     self.currentView = nil; 
    } 
} 

này làm việc cho tôi trên iOS 5.

+0

Đây là giải pháp tôi thực hiện cũng như –

+0

y nó đang thay đổi hướng của thiết bị – WaaleedKhan

1

Đây là mã tôi sử dụng trong một trong các ứng dụng của mình. Nó miễn nhiệm.

NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/us/app/packager/id459511278?l=nl&ls=1&mt=8"]; 
NSString *twittertext = [[NSString alloc] initWithFormat: @"Tweet Text"]; 
SHKItem *item = [SHKItem URL:url twittertext]; 

// Share the item 
[SHKTwitter shareItem:item]; 
[twittertext release]; 
+0

Nếu bạn thực hiện [NSString stringWithFormat: @ "Tweet Text"]; và xóa [twittertext release]; dòng, nó vẫn bỏ? Rõ ràng sự khác biệt duy nhất là tôi đang sử dụng ARC ... – cfischer

1

Tôi đã sử dụng đoạn mã sau vào ứng của tôi (ARC tàn tật)

NSString *text = @"Go away, modal view controller!"; 

[SHKTwitter shareText:text]; 

Tôi có thể khẳng định nó bác bỏ tốt. Bạn có thể đã thay đổi một số mã trong SHKTwitterForm.m khi cố gắng làm cho Sharekit ARC tương thích. Kết quả là lỗi của bạn

+0

Không, tôi chỉ biên dịch tất cả các tệp ShareKit mà không cần ARC: -fno-objc-arc – cfischer

+0

Tôi chỉ đọc lại câu hỏi ban đầu của bạn và tìm thấy một số nhầm lẫn đang sử dụng Xcode 4.3? Ngoài ra, phiên bản giả lập nào bạn gặp phải lỗi? Bạn đã thử nghiệm nó trên một thiết bị thực sự là tốt? – Louis

2
if (isDismissingView) 
    return; 

if (currentView != nil) 
{ 
    // Dismiss the modal view 
    if ([currentView parentViewController] != nil) 
    { 
     self.isDismissingView = YES; 
     [[currentView parentViewController] dismissModalViewControllerAnimated:animated]; 
    } 

    else { 
     //## ADD BELOW ## 
     self.isDismissingView = YES; 
     [currentView dismissModalViewControllerAnimated:animated]; 
     self.currentView = nil; 

    } 
} 
else { 
    [[self getTopViewController].navigationController popViewControllerAnimated:YES]; 
} 
Các vấn đề liên quan