我有一个表名称数组,希望循环遍历它们并获取它们的名称并附加一个URL来创建与Web服务的连接以下载JSON数据.循环似乎首先工作,数组中的三个表名中的每一个都被用于创建与Web服务的连接并且数据被下载但是当循环结束时(从3变为0)循环出现再次启动并为数组中的最后两个表无限循环.
记录输出(注意扬声器和参展商反复重复):
2013-12-16 10:38:08.755 WebServiceTest[501:60b] loopCount = 3
2013-12-16 10:38:08.758 WebServiceTest[501:60b] table name = workshop
2013-12-16 10:38:08.817 WebServiceTest[501:60b] LoopCount is: 2
2013-12-16 10:38:08.821 WebServiceTest[501:60b] loopCount = 2
2013-12-16 10:38:08.822 WebServiceTest[501:60b] table name = exhibitor
2013-12-16 10:38:08.827 WebServiceTest[501:60b] LoopCount is: 1
2013-12-16 10:38:08.830 WebServiceTest[501:60b] loopCount = 1
2013-12-16 10:38:08.831 WebServiceTest[501:60b] table name = speaker
2013-12-16 10:38:08.835 WebServiceTest[501:60b] LoopCount is: 0
2013-12-16 10:38:09.199 WebServiceTest[501:3707] Status code = 200
2013-12-16 10:38:09.204 WebServiceTest[501:3707] Objects in current table - speaker = 1
2013-12-16 10:38:09.207 WebServiceTest[501:3707] …Run Code Online (Sandbox Code Playgroud) 背景:我有一个UIViewController,当加载时,以UITableView编程方式生成从SQLite3数据库获取其数据.这很好用.
问题:我需要添加一个UISearchBar(和相关的逻辑),但是当我尝试时,UISearcBar不会被渲染.
代码到目前为止:
.h文件:
#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import "Exhibitor.h"
@interface ExhibitorViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
{
sqlite3 *congressDB;
NSMutableArray *searchData;
UISearchBar *searchBar;
UISearchDisplayController *searchDisplayController;
}
@property (strong, nonatomic) IBOutlet UITableView *tableView;
-(NSString *) filePath;
-(void)openDB;
@end
Run Code Online (Sandbox Code Playgroud)
添加UISearchBar的.m文件:
-(void)loadTableView
{
CGRect usableSpace = [[UIScreen mainScreen] applicationFrame];
CGFloat usableWidth = usableSpace.size.width;
CGFloat usableHeight = usableSpace.size.height;
UITableView *tableView = [[UITableView alloc] init];
[tableView setFrame:CGRectMake(0,0,usableWidth, usableHeight)];
tableView.dataSource = self;
tableView.delegate = …Run Code Online (Sandbox Code Playgroud) 我认为这应该是一个简单的,但我只是在挠头.我有一个应用程序,在故事板中设置了多个ViewControllers.我希望每个视图的每个视图顶部都有相同的导航栏,但是这个导航控制器在所有视图上都有相同的按钮.导航控制器在AppDelegate中设置,按钮添加到每个ViewController的ViewDidLoad中(根据我在这里收到的另一个问题的答案),但此时,按钮(和标题)没有显示.
设置UINavigationController的位置 - AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
MainViewController* mainVC = [mainStoryboard instantiateInitialViewController];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
[self.window setRootViewController:navVC];
[_window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
其中一个观点:
- (void)viewDidLoad
{
[self setTitle:@"Congress app"]; // < This does not set the title of the NavController
UIBarButtonItem *showSettingsButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showSettings:)];
UIBarButtonItem *showMenuButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"menuButton.png"] style:UIBarButtonItemStylePlain target:self action:@selector(revealMenu:)];
//self.navigationItem.leftBarButtonItem = showMenuButton;
//self.navigationItem.rightBarButtonItem = showSettingsButton;
self.navigationController.navigationItem.leftBarButtonItem = showMenuButton; …Run Code Online (Sandbox Code Playgroud)