小编Mox*_*oxy的帖子

更改tableview的插入时UITableView中的节标题

我已经在我的tableView中实现了"Pull to refresh",就像iPhone应用程序Twitter或Facebook一样.
我的tableView包含带有头部视图的部分.当tableView处于"刷新模式"时,所以当我拉取tableView进行刷新时,我设置tableView的contentInset以某种方式显示tableView.此时,如果我将tableView向上推,则UITableView的标题不再滚动到UITableView的顶部.请参阅以下屏幕截图:

截图1

截图2

我如何解决这个问题,使标题滚动像预期的那样?

谢谢!

iphone cocoa objective-c

17
推荐指数
1
解决办法
9667
查看次数

如何使用Facebook ios sdk 3.0将5张图像附加到Facebook Feed帖子

我正在尝试向用户的帖子发送这样的内容(它最初只显示一个图像,但是当您点击"显示更多"时,您会看到所有五个图像)

发布5张图片

我的代码看起来像这样:

NSMutableArray *properties = [[NSMutableArray alloc] initWithCapacity:5];
NSMutableArray *media = [[NSMutableArray alloc] initWithCapacity:5];
for (MyObject *object in self.myObjects) {
    [properties addObject:[NSDictionary dictionaryWithObjectsAndKeys:object.name,@"text",
                                                                     object.link,@"href", nil]];
    NSString *imageUrlString = object.url.absoluteString;
    [media addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"image",@"type",
                                                                imageUrlString,@"src",
                                                                object.link,@"href", nil]];
}
NSData *propertyData = [NSJSONSerialization dataWithJSONObject:properties
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:nil];
NSString *propertiesString = [[NSString alloc] initWithData:propertyData
                                                   encoding:NSUTF8StringEncoding];
NSData *mediaData = [NSJSONSerialization dataWithJSONObject:media
                                                    options:NSJSONWritingPrettyPrinted
                                                      error:nil];
NSString *mediaString = [[NSString alloc] initWithData:mediaData
                                              encoding:NSUTF8StringEncoding];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:myAppID, @"app_id",
                                                                  link, @"link",
                                                                  name, @"name",
                                                                  caption, @"caption",
                                                                  propertiesString, @"properties",
                                                                  mediaString, @"media", …
Run Code Online (Sandbox Code Playgroud)

facebook facebook-graph-api ios ios5 facebook-feed

17
推荐指数
1
解决办法
4687
查看次数

UIViewController扩展不允许在Swift中覆盖与视图相关的函数?

在尝试为UIViewController实现扩展时,我意识到没有正常的方法,或者不允许覆盖这些函数(即使它们可用于UICollectionViewControllerUITableViewController):

extension UIViewController{
  public override func viewWillAppear(){
    super.viewWillAppear()
    //do some stuff
 }
}
Run Code Online (Sandbox Code Playgroud)

我意识到没有正常的方法,或者不允许覆盖这些函数(即使它们可用于UICollectionViewControllerUITableViewController):

  • viewDidLoad中
  • viewWillLoad
  • viewWillAppear中
  • viewDidAppear

有一些方法可以做到这一点?我想在那里有一些实现,并为我的应用程序上的每个UIViewController工作...所有在一个地方.

请注意,不想创建一个新类继承UIViewController,重写这些方法并让我的控制器扩展它.这是一个显而易见且最简单的解决方案,但这并不能满足我的目标.

我在XCode 6.3中使用swift 1.2

uiviewcontroller ios swift ios8

17
推荐指数
1
解决办法
2万
查看次数

NSHTTPCookieStorage的共享实例不会保留cookie

我正在开发一个应用程序,其中服务器递给我一个cookie来识别用户.

我的连续请求需要使用该cookie来获得用户期望的响应.我无法理解的是NSHTTPCookieStorage的共享实例如何以及何时丢失其cookie.

我使用的第一个解决方案是将cookie从我的服务器存档并保存到应用程序终端的用户默认值,然后在应用程序启动时从我的服务器清除现有的cookie并重置我存储的那些.通过开发过程我没有遇到问题,因为调试会话非常短,通常不需要将应用程序放在后台.

在beta测试期间,麻烦开始了.我带来的黑客攻击不仅是在应用程序终止时保存cookie,而且还在API调用后将这些cookie保存回来.并且不仅在应用程序启动时加载已保存的cookie,而且还在应用程序返回到前台时加载.

为什么NSHTTPCookieStorage共享实例摆脱了这些cookie以及处理它的最佳实践是什么,因为它是我的应用程序的重要部分,如果没有经验丰富的开发人员支持,我不能相信这样一个被黑客入侵的解决方案.

提前感谢您的回答

编辑:以下是保存/读取/清除cookie的方法

-(void)saveStoredCookies
{
    NSURL *httpUrl = @"http://myServer.com";
    NSURL *httpsUrl = @"https://myServer.com";

    NSArray *httpCookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:httpUrl];
    NSData *httpCookiesData = [NSKeyedArchiver archivedDataWithRootObject:httpCookies];
    [[NSUserDefaults standardUserDefaults] setObject:httpCookiesData forKey:@"savedHttpCookies"];

    NSArray *httpsCookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:httpsUrl];
    NSData *httpsCookiesData = [NSKeyedArchiver archivedDataWithRootObject:httpsCookies];
    [[NSUserDefaults standardUserDefaults] setObject:httpsCookiesData forKey:@"savedHttpsCookies"];

    [[NSUserDefaults standardUserDefaults] synchronize];
}

-(void)readStoredCookies
{
    //clear, read and install stored cookies
    NSURL *httpUrl = @"http://myServer.com";
    NSURL *httpsUrl = @"https://myServer.com";

    NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:httpUrl];
    for (NSHTTPCookie *cookie in cookies) {
        [[NSHTTPCookieStorage …
Run Code Online (Sandbox Code Playgroud)

iphone nshttpcookie ios ios5

14
推荐指数
3
解决办法
2万
查看次数

如何连接3个NSData变量

如何连接3个NSData变量?

NSData *iv;
NSData *salt;
NSData *encryptedData;
Run Code Online (Sandbox Code Playgroud)

我需要将这些加入一个变量.任何人都可以告诉我一个方法.

iphone ios4 ios ios5

14
推荐指数
1
解决办法
9406
查看次数

如何对NSURLConnection代表进行单元测试?

我如何对我的NSURLConnection代表进行单元测试?我创建了一个ConnectionDelegate类,它符合不同的协议,以便将数据从Web提供给不同的ViewControllers.在我走得太远之前,我想开始编写单元测试.但我不知道如何在没有互联网连接的情况下将它们作为一个单元进行测试.我还想对待异步回调我应该怎么做.

unit-testing ocmock nsurlconnection ios nsurlconnectiondelegate

11
推荐指数
4
解决办法
9284
查看次数

UISearchBar自动调整大小并更改帧

我有一个搜索栏的问题,当它变成a firstResponder并且它何时退出时,它会以一种奇怪的方式运行.

搜索栏将添加为表视图的标题

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 44.0f)];
self.searchBar.translucent = NO;
self.searchBar.barTintColor = [UIColor grayColor];
self.tableView.tableHeaderView = self.searchBar;

self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar
                                                          contentsController:self];
self.searchController.searchResultsDataSource = self;
Run Code Online (Sandbox Code Playgroud)

视图控制器设置为左侧面板,JASidePanelController当键盘显示或隐藏时,它会隐藏中央面板:

- (void)keyboardWillAppear:(NSNotification *)note
{
    [self.sidePanelController setCenterPanelHidden:YES
                                          animated:YES
                                          duration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
    self.searchBar.showsCancelButton = YES;
}

- (void)keyboardWillDisappear:(NSNotification *)note
{
    [self.sidePanelController setCenterPanelHidden:NO
                                          animated:YES
                                          duration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
    self.searchBar.showsCancelButton = NO;
}
Run Code Online (Sandbox Code Playgroud)

正常状态 正常状态

当搜索栏变为a时,firstResponder它会向上移动一个点或随机向下移动

点了 指向下方



当搜索栏退出时,它会动画到达窗口原点,然后返回其自然帧

伸展

到达原点

这是一个重现错误的示例项目.

编辑:

根据@kwylez的 建议,可以通过以下方式避免搜索栏在重新签名时产生的不需要的动画:

self.searchBar.clipsToBounds = YES;
Run Code Online (Sandbox Code Playgroud)

uisearchbar uisearchdisplaycontroller ios

11
推荐指数
2
解决办法
7740
查看次数

滚动浏览屏幕后,UITableView不会反弹

这是一个正在发生的事情的视频:https://imgflip.com/gif/kgvcq

基本上,如果单元格滚动超过屏幕的下边缘,它将不会反弹.我试着更新contentSize了的tableView似乎并不成为问题,但.我也确保宣布rowHeight并且仍然没有运气.最后,我确保正确设置bounce属性tableView.

嗨,大家好抱歉没有提供代码,这里是:

// data source
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"frame height: %f", tableView.frame.size.height);
    NSLog(@"content size height: %f", tableView.contentSize.height);

    static NSString *CellIdentifier = @"HabitCell";

    HabitTableViewCell *cell = (HabitTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.viewController = self;
    cell.delegate = self;

    // edit cell

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

NSLogs分别568和400:正在返回.是框架会导致问题吗?另外,我还没有覆盖scrollViewDidScroll.

实施数据源方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [self.habits …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

11
推荐指数
1
解决办法
510
查看次数

performSegueWithIdentifier不起作用

我的主视图控制器在导航控制器中,它符合EditViewControllerDelegate协议.它是我的两个视图控制器的代表,我需要以模态方式呈现.

@interface EditViewController : UIViewController
@property (nonatomic) id <EditViewControllerDelegate> delegate;
@end

@interface EditSomethingViewController : EditViewController
@end

@interface EditSomethingElseViewController : EditViewController
@end
Run Code Online (Sandbox Code Playgroud)

在一个 editViewController:(EditViewController *)evc didFinishEditing:(Something *) something 方法中,我首先得到我需要的数据然后我解雇evc并调用

[self performSegueWithIdentifier:@"My Segue" sender:self];
Run Code Online (Sandbox Code Playgroud)

"My Segue"在Xcode中定义,标识符在代码和Xcode中都是相同的(我试图改变它只是为了看它是否被调用并引发异常)

当我改变"我的Seque"的类型推动时,它起作用了.但是在使用模态后,它在我回到主视图控制器后没有做任何事情

我错过了什么?

编辑:

我不小心在故事板上发现了一个警告!(这很奇怪,因为它不是项目中的警告"从任何地方都可见")在"引用故事板Segues"下的连接检查器中,我的模态segue有一个警告.它说 :

(null) is not a valid containment controller key path
Run Code Online (Sandbox Code Playgroud)

我检查了其他模态segue并且有相同的警告,但我不需要通过代码触发它们,所以之前没有问题.

编辑2:

-(void)editViewController:(EditViewController *) evc
didFinishEditing:(Something *) something
{
    self.something = something;
    [self dismissModalViewControllerAnimated:YES];
    For ( OtherThing * otherThing in self.something.otherthingsArray)
    {
        NSLog(@"%@", otherThing);
    }
    [self performSegueWithIdentifier:@"My Segue" …
Run Code Online (Sandbox Code Playgroud)

iphone ios5 uistoryboard segue xcode4.3

8
推荐指数
1
解决办法
1万
查看次数

iOS应用程序在后台崩溃,因为更改了设置 - >隐私 - >联系我的应用程序开启/关闭

在我的应用程序中我收到联系信息直接购买这样做...

ABAddressBookRef m_addressbook = ABAddressBookCreate();

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);

CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

for (int i=0;i < nPeople;i++)
{
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
    CFStringRef company,firstName,lastName;

     firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
     lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty);
     company = ABRecordCopyValue(ref, kABPersonOrganizationProperty);
}
Run Code Online (Sandbox Code Playgroud)

因此,我需要首先检查这是否为我的应用程序的开/关设置 - >隐私 - >联系人开/关.

为此,我这样做:

__block BOOL accessGranted = NO;


float sysver = [[[UIDevice currentDevice]systemVersion]floatValue];

if(sysver>=6) {
    ABAddressBookRef addressBook = ABAddressBookCreate();

    if (ABAddressBookRequestAccessWithCompletion != NULL) {  
        dispatch_semaphore_t sema = dispatch_semaphore_create(0);
        ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
            accessGranted = granted;
            dispatch_semaphore_signal(sema);});

     dispatch_semaphore_wait(sema, …
Run Code Online (Sandbox Code Playgroud)

ios

8
推荐指数
1
解决办法
3163
查看次数