我知道这是非常基本的,但我到处寻找,我找不到正确的答案.
参考我之前的一个问题:如何在PHP中格式化列表以用作Objective C中的NSArray?
我一直在尝试编写一个简短的PHP脚本(对此一无所知)我的iphone应用程序将调用以获取项目列表.我想过只使用ECHO,因为我真的不需要发送多个项目数组,但建议使用JSON或XML,所以选择了JSON.
我正在寻找一种方法将数组编码为JSON,我唯一能找到的是json_encode似乎没有提供JSON结构.这是我的PHP代码:
<?php
$arr = array ('a', 'b','c','d','e');
echo json_encode($arr);
?>
Run Code Online (Sandbox Code Playgroud)
这是我应该使用的吗?我做错了吗?非常感谢.
编辑:
在终端中运行此PHP脚本时输出:
[ "一", "B", "C", "d", "E"]
据我所知,这不是一个JSON结构,但我再也不知道它.
我做了一些关于这个的讨论,但似乎没有什么能回答我的特定问题(甚至没有这个问题:是否可以用动画删除SuperSuperview?).
基本上,我的应用程序以欢迎屏幕开始,用户点击"登录",然后转到登录视图,然后转到标签栏视图,这是实际的应用程序.
我这样做的方法是,我编写了一个自定义类 - TabBarController,它设置了所有选项卡及其各自的视图控制器.现在,当用户点击"登录"时,我正在调用removeFromSuperview并显示标签栏.
我试图找到一种方法来设置从登录页面到标签栏的过渡动画.我在这里尝试了一些提议的解决方案,但似乎都没有做到这一点.这是我在signin.m视图控制器中的代码.我希望为当前视图制作动画(理想情况下,不仅仅是淡出,而是更多很酷的东西,如翻转等).
//when done signing in --> go to the tab bar view
-(IBAction)done:(id)sender {
TabBarController *tabController = [[TabBarController alloc] init];
[UIView beginAnimations:@"removeWithEffect" context:nil];
[UIView setAnimationDuration:4.0];
self.parentViewController.view.frame = CGRectMake(0,0,320,480);
self.parentViewController.view.alpha = 1.0f;
[UIView commitAnimations];
[self.parentViewController.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.5f];
[self presentModalViewController:tabController animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助!
我查了很多这种方法的例子,但仍然无法弄清楚我在做什么.我正在尝试在当前视图下添加另一个视图,然后在用户单击当前屏幕上的按钮时删除当前视图.由于某种原因,视图消失了,但我没有看到应该低于它的视图.我只是一个白色的屏幕.
这是我当前的ViewDidLoad(顶部的那个 - 为了示例的ViewControllerTop)视图:
- (void)viewDidLoad
{
[super viewDidLoad];
viewControllerBottom = [[ViewControllerBottom alloc] init];
[self.view insertSubview:viewControllerBottom.view belowSubview:self.view];
}
Run Code Online (Sandbox Code Playgroud)
按照这种方法,有一种方法在用户点击按钮后触发:
- (IBAction)goToBottomView:(id)sender {
[self.view.superview removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
有没有人看到这个有什么问题?谢谢您的帮助!
顺便说一句 - 即使它很愚蠢,我也尝试使用insertSubview:aboveSubview但它也不起作用.
我正在构建一个使用UPC数据库API的应用程序.我回到了一个JSON对象,例如:http://www.simpleupc.com/api/methods/FetchNutritionFactsByUPC.php
{
"success":true,
"usedExternal":false,
"result"
{
"calories_per_serving":"150",
"cholesterol_per_serving":"15",
"cholesterol_uom":"Mg",
"dvp_calcium":"30",
"dvp_cholesterol":"4",
"dvp_iron":"2",
"dvp_protein":"17",
"dvp_saturated_fat":"8",
"dvp_sodium":"10",
"dvp_total_fat":"4",
"dvp_vitamin_a":"10","
"dvp_vitamin_c":"0",
"dvp_vitamin_d":"25",
"fat_calories_per_serving":"25",
"fiber_per_serving":"<1",
"fiber_uom":"G",
"ingredients":"Fat Free Milk, Milk, Sugar, Cocoa (Processed With Alkali),
Salt, Carrageenan, Vanillin (Artificial Flavor),
Lactase Enzyme, Vitamin A Palmitate And Vitamin D3.",
"protein_per_serving":"8",
"protein_uom":"G",
"size":"240",
"units":"mL",
"servings_per_container":"8",
"sodium_per_serving":"230",
"sodium_uom":"Mg",
"total_fat_per_serving":"2.5",
"total_fat_uom":"G",
"trans_fat_per_serving":"0",
"trans_fat_uom":"G",
"upc":"041383096013"
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是解析"ingredients"元素,它是对象字典的子列表.
您如何建议解析成分列表?如果我能把它送到NSArray,假设逗号是分隔符,那就太好了.
我试图这样做,但看起来只是一个字符串,所以无法解析它.
任何建议都会受到欢迎.谢谢!
//Thats the whole JSON object
NSDictionary *json_dict = [theResponseString JSONValue];
//Getting "results" which has all …Run Code Online (Sandbox Code Playgroud) 我试图找到一种方法为我的应用程序中的不同导航栏设置不同的背景颜色(我有几个视图,每个导航栏).我不打算覆盖drawRect:因为它适用于整个应用程序.此外,使用tintcolor属性没有帮助,因为它仅适用于导航栏项.
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
Run Code Online (Sandbox Code Playgroud)
我已经谷歌搜索了几天,无法找到解决这个问题的直接解决方案.怎么这么简单就这么难?不明白为什么它不是uinavbar的属性......
有人请帮忙解决一个简单的问题...谢谢!
iphone xcode objective-c uinavigationbar uinavigationcontroller
我确信这真的很愚蠢,但我似乎无法理解为什么我会收到这个错误.在我的项目中,我有一个视图控制器和另一个做一些数据结构工作的类(无论如何都不相关).我收到一个编译错误:"未知类型名称"视图控制器""试图在我的类中实例化它.
这是我的班级.h:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import "MyLocationController.h"
#import "GetZip.h"
#import "SecondTab.h"
@interface DataEngine : NSObject <MyLocationControllerDelegate, MKMapViewDelegate, GetZipcodeDelegate> {
MyLocationController *CLController;
GetZip *getzip;
SecondTab *secondTab; //ERROR IS HERE
}
Run Code Online (Sandbox Code Playgroud)
我的视图控制器.h:
#import <UIKit/UIKit.h>
#import "FirstTab.h"
#import "DataEngine.h"
@interface SecondTab : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *table1;
NSString *address;
NSDate *time;
NSDictionary *dataDict;
DataEngine *fullData;
}
Run Code Online (Sandbox Code Playgroud)
(我省略了所有@synthesis,因为我认为它们不重要......无论如何,我做@property(非原子,保留)的一切).
知道这里可能出现什么问题吗?
我从apple dev库中逐行复制了这个方法,并获得了两个NSString强制转换的转换错误.怎么解决这个问题?(我正在使用ARC)
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
NSString* name = (NSString *)ABRecordCopyValue(person,
kABPersonFirstNameProperty);
self.firstName.text = name;
name = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
self.lastName.text = name;
[self dismissModalViewControllerAnimated:YES];
return NO;
}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
我有一个视图控制器,我希望能够通过导航栏上的右上角"完成"按钮解除.我没有使用uinavcontoller,但只是在我的viewDidLoad中添加了这样的导航栏:
bar = [[UINavigationBar alloc] init];
Run Code Online (Sandbox Code Playgroud)
在.h:
IBOutlet UINavigationBar *bar;
Run Code Online (Sandbox Code Playgroud)
当然,连接IB上的导航栏.
然后我尝试在viewDidLoad中添加一个导航项,但没有任何反应:
rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonSystemItemDone target:nil action:nil];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];
item.rightBarButtonItem = rightButton;
item.hidesBackButton = YES;
[bar pushNavigationItem:item animated:NO];
Run Code Online (Sandbox Code Playgroud)
请注意 - 这里有几个问题,但没有一个回答这个问题.
谢谢您的帮助!
iphone xcode objective-c uinavigationbar uinavigationcontroller
我正在尝试为我的导航栏添加标题,我已经以编程方式添加了该标题.我知道我可以创建一个标签并将其添加为子视图,但是我需要添加大量的配置才能正确放置,就像在典型的导航栏标题中一样.有没有其他方法可以做到这一点:
- (void)viewDidLoad
{
[super viewDidLoad];
//Adding navBar programmatically
CGFloat width = self.view.frame.size.width;
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0,width,52)];
navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
//Adding title programmatically
UILabel *lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(10,10,80,30)];
lblTitle.text = @"Title";
[navBar addSubview: lblTitle];
[self.view addSubview:navBar];
}
Run Code Online (Sandbox Code Playgroud)
如果不是(对不起另一个问题,只是认为它有关)我如何设置我的lblTitle看起来像你会在大多数应用程序中找到的普通导航栏标题.
谢谢!
我有一个字符串,其中包含一些带句点和逗号的文本.我想根据逗号和句点将其转换为NSArray.我使用这种方法根据一种条件进行分离,但是如何用两种方法进行分离呢?
componentsSeparatedByString:
Run Code Online (Sandbox Code Playgroud)
谢谢.
我希望将原生的"+"符号添加到我的一个tableview单元格中,但不确定是否有属性.我基本上想在下面的图像中做什么,但是在非编辑模式下(我知道在编辑模式下如何做到这一点).我是否需要手动添加此图像,还是作为tableview单元格API的一部分提供?
谢谢!

我正在构建一个iphone应用程序,它从地址簿中读取一个电话号码并拨打它(当然还有其他一些东西...... :)).当我从AB加载电话号码时,它们采用以下格式:"1(111)111-1111"使用时不能"拨号":
fullNumber = [NSString stringWithFormat:@"%@%@", @"tel:", phoneNum];
Run Code Online (Sandbox Code Playgroud)
为什么会这样?什么是最好的方法来解决这个问题?我怎么能将电话号码转换成一串数字(没有空格或" - ")?
谢谢.
没有调用协议方法的另一种情况 - 不知道我在这里做错了什么...
这是代码,省略不必要的信息......
第一个头文件:AccessNumber.h
@protocol AddItemDelegate <NSObject>
@required
- (void) processSuccessful: (BOOL)success;
@end
@interface AccessNumber : UIViewController <UITableViewDelegate, UITableViewDataSource, ABPeoplePickerNavigationControllerDelegate, UIAlertViewDelegate> {
id <AddItemDelegate> delegate;
}
@property (retain) id <AddItemDelegate> delegate;
@end
Run Code Online (Sandbox Code Playgroud)
第一.m文件:AccessNumber.m - 我打电话从viewDidLoad中协议方法只是为了测试目的,它应该基本上得到来自另一种方法调用,但对于这个康沃的缘故一样的东西(都尝试当然)
#import "AccessNumber.h"
#import "History.h"
@synthesize delegate;
- (void)viewDidLoad
{
[super viewDidLoad];
....
[[self delegate] processSuccessful:YES];
}
Run Code Online (Sandbox Code Playgroud)
第二个文件头:History.h
@interface History : UIViewController <UITableViewDelegate, UITableViewDataSource, AddItemDelegate> {
....
}
Run Code Online (Sandbox Code Playgroud)
历史中的方法实现
- (void) processSuccessful: (BOOL)success {
NSLog(@"SUCCESS");
}
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助.谢谢!