我想创建一个使用UITabBarController的应用程序,它类似于iPhone和iPod touch的Twitter应用程序.(用于在内容视图之间切换的未读和滑动箭头的蓝灯).
是否有捷径可寻?任何开源代码?
编辑:
我加了一笔赏金.我正在寻找适用于各种设备以及iOS 4和iOS 5的解决方案.
编辑:
我搞砸了我的原始代码,我找到了一个简单的解决方案.我在动画代码中为iOS 5添加了以下检查:
// iOS 5 changes the subview hierarchy
// so we need to check for it here
BOOL isUsingVersionFive = NO;
NSString *reqSysVer = @"5.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending){
//On iOS 5, otherwise use old index
isUsingVersionFive = YES;
}
Run Code Online (Sandbox Code Playgroud)
然后,而不是这个:
CGFloat tabMiddle = CGRectGetMidX([[[[self tabBar] subviews] objectAtIndex:index] frame]);
Run Code Online (Sandbox Code Playgroud)
......我用这个:
CGFloat tabMiddle = CGRectGetMidX([[[[self tabBar] subviews] objectAtIndex:index + (isUsingVersionFive ? 1 : 0)] …Run Code Online (Sandbox Code Playgroud) 我想用逗号或更好的格式化我的UILabel,带有美元符号和逗号(没有小数).
这是我正在使用的代码:
IBOutlet UILabel *labelrev
float rev = (x + y)
labelrev.text = [[NSString alloc] initWithFormat:@%2.f",rev];
Run Code Online (Sandbox Code Playgroud)
我得到xxxxxxxxx作为输出我想得到xxx,xxx,xxx或$ xxx,xxx,xxx
我怎么做?
哪种Objective-c类型适合处理钱?我需要一些与Core Data兼容的东西.
我有一个像这样打印的数组
Array ( [0] => 1691864 [1] => 7944458 [2] => 9274078 [3] => 1062072 [4] => 8625335 [5] => 8255371 [6] => 5476104 [7] => 6145446 [8] => 7525604 [9] => 5947143 )
Run Code Online (Sandbox Code Playgroud)
如果我json_encode($thearray)得到这样的东西
[1691864,7944458,9274078,1062072,8625335,8255371,5476104,6145446,7525604,5947143]
Run Code Online (Sandbox Code Playgroud)
为什么名称没有编码(例如0,1,2,3等)?我应该如何使它出现在json代码中?完整的代码如下
$ie = 0;
while($ie 10)
{
$genid = rand(1000000,9999999);
$temp[$ie] = $genid ;
$ie++;
}
print_r($temp);
$temp_json = json_encode($temp);
print_r($temp_json);
Run Code Online (Sandbox Code Playgroud) 我正在研究Fahrii,它本质上是一个支持用户脚本的移动浏览器.目前,我在加载到UIWebView的网页上调用脚本时遇到问题.如果可能的话,我想保留这些公共API.如果没有,概念证明至少会很好,所以我可以更好地理解它是如何工作的.我试图在webViewDidFinishLoad:方法中这样做.
我尝试通过读取webView的内容(使用JavaScript)进行注入,然后将其加载回来loadHTML:baseURL:,但这会导致无限递归.(完成的加载会导致脚本被注入,这反过来导致完成"加载".)
接下来,我尝试过这样的事情:
[self.browser stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.innerHTML = %@", originalHTMLWithScriptsInjected]];
Run Code Online (Sandbox Code Playgroud)
脚本似乎是注入的,但没有运行.
我使用它的唯一方法是使用ASIHTTPRequest库来发出实际请求,但最后我遇到了登录表单的问题,除此之外,我必须在这种情况下每次请求两次.
我可能会做一些不可能的事情,或者我只是做错了.那么,如何在现有的UIWebView上调用带有从Web加载的内容的用户脚本?
编辑:
这里有一些代码,包括@rich提出的更改:
//
// Run the remaining scripts
//
NSMutableString *scriptTextToInject = [[NSMutableString alloc]init];
//
// Add each script into the page
//
for (Userscript *script in scriptsToExecute) {
//
// Read the userscript
//
NSString *scriptToLoad = [NSString stringWithContentsOfURL:[NSURL URLWithString:script.pathToScript] encoding:NSUTF8StringEncoding error:&error];
NSLog(@"Script to load: %@", scriptToLoad);
[scriptTextToInject appendFormat:@"%@\n\n",scriptToLoad];
}
NSString *documentHeadBefore = [self.browser stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('head')[0].innerHTML"];
//
// Inject the scripts …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用自定义类声明一个数组.当我向类中添加构造函数时,我的编译器抱怨"没有用于初始化name [3]的匹配构造函数".
这是我的计划:
#include <iostream>
using namespace std;
class name {
public:
string first;
string last;
name(string a, string b){
first = a;
last = b;
}
};
int main (int argc, const char * argv[])
{
const int howManyNames = 3;
name someName[howManyNames];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能实现这一目标,我做错了什么?
我正在使用ARC,并在循环中修改字符串时看到一些奇怪的行为.
在我的情况下,我使用NSXMLParser委托回调循环,但我看到使用演示项目和简单修改某些NSString对象的示例代码的相同的确切行为和症状.
您可以从GitHub下载演示项目,只需在主视图控制器的viewDidLoad方法中取消注释四个方法调用之一,即可测试不同的行为.
为简单起见,这是一个简单的循环,我已经陷入了一个空的单视图应用程序.我将此代码直接粘贴到viewDidLoad方法中.它在视图出现之前运行,因此屏幕为黑色,直到循环结束.
NSString *text;
for (NSInteger i = 0; i < 600000000; i++) {
NSString *newText = [text stringByAppendingString:@" Hello"];
if (text) {
text = newText;
}else{
text = @"";
}
}
Run Code Online (Sandbox Code Playgroud)
以下代码在循环完成之前还会保留内存:
NSString *text;
for (NSInteger i = 0; i < 600000000; i++) {
if (text) {
text = [text stringByAppendingString:@" Hello"];
}else{
text = @"";
}
}
Run Code Online (Sandbox Code Playgroud)
以下是这两个循环在Instruments中循环的方式,运行Allocations工具:

看到?逐渐稳定的内存使用,直到一大堆内存警告,然后应用程序自然死亡.
接下来,我尝试了一些不同的东西.我使用了一个实例NSMutableString,如下:
NSMutableString *text;
for (NSInteger i = …Run Code Online (Sandbox Code Playgroud) memory-management objective-c instruments nsstring automatic-ref-counting
iOS上的Spotify有一个非常有趣的控制中心集成.注意下面的汉堡包按钮.

锁屏上同样的事情!

他们是如何做到的?MPMediaCenter中有API吗?
我正在开发一个文本视图,用UITextFields替换占位符.我传递了一个对象(结构或字典),其中包含多个占位符令牌实例的文本.该字典还包含我们想要从中收集数据的字段数组.我的目标是在我的文本中放置UITextFields(或其他视图),并隐藏令牌.
使用NSLayoutManager方法计算文本容器中占位符标记的位置,我将这些点转换为CGRects然后排除路径到文本字段周围.这是看起来像:
func createAndAssignExclusionPathsForInputTextFields () {
var index = 0
let textFieldCount = self.textFields.count
var exclusionPaths : [UIBezierPath] = []
while index < textFieldCount {
let textField : AgreementTextField = self.textFields[index]
let location = self.calculatePositionOfPlaceholderAtIndex(index)
let size = textField.intrinsicContentSize()
textField.frame = CGRectMake(location.x, location.y, size.width, size.height)
exclusionPaths.append(textField.exclusionPath())
index = index + 1
}
self.textContainer.exclusionPaths = exclusionPaths
}
Run Code Online (Sandbox Code Playgroud)
// ...
func calculatePositionOfPlaceholderAtIndex(textIndex : NSInteger) -> CGPoint {
let layoutManager : NSLayoutManager = self.textContainer.layoutManager!
let delimiterRange = self.indices[textIndex]
let characterIndex = …Run Code Online (Sandbox Code Playgroud) ios ×4
objective-c ×4
arrays ×2
php ×2
browser ×1
c++ ×1
constructor ×1
currency ×1
formatting ×1
instruments ×1
iphone ×1
json ×1
layout ×1
nsstring ×1
textkit ×1
twitter ×1
types ×1
uilabel ×1
uitextview ×1
uiwebview ×1
userscripts ×1