我正在使用以下代码订阅我自己的通知:
NSNotificationCenter.DefaultCenter.AddObserver("BL_UIIdleTimerFired", delegate {
Console.WriteLine("BaseFolderViewController: idle timer fired");
});
Run Code Online (Sandbox Code Playgroud)
要发送通知:
NSNotificationCenter.DefaultCenter.PostNotificationName("BL_UIIdleTimerFired", null);
Run Code Online (Sandbox Code Playgroud)
但是,只有在"anObject"参数PostNotificationName(string sString, object anObject)不为NULL 时才会正确接收通知.
这是设计的吗?我必须传递一个物体吗?或者这是一个错误?我真的不想发送对特定对象的引用.
我目前正在模拟器中运行我的应用程序时查看Monotouch内存分析器的输出.我可以看到这些数字:
Object count: 154.043
Total memory: 5.099.648 bytes
Run Code Online (Sandbox Code Playgroud)
"总内存"是什么意思,我占用了大约5MB的内存?仪器向我展示了大约30MB的分配,这就是我要问的原因.
我已经看到Xcode中有很多方法可以设计你的CoreData模型 - 有没有办法在MonoTouch 5中使用它和CoreData?任何教程或示例?
我正在使用
string version = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString();
Run Code Online (Sandbox Code Playgroud)
获取我的应用程序的版本.它设置为1.2.0

但是上面的代码返回1.0.我已经重新创建了info.plist而没有成功.我知道我在以前的项目中使用了相同的代码,所以改变了什么?
当然,我已经尝试过清理和重建.
Xamarin Studio版本4.1.12(版本6)安装UUID:b8bdc5a1-348b-4fad-8e4f-4632ee990c59运行时:Mono 3.2.3((no/8d3b4b7)GTK + 2.24.20主题:Raleigh GTK#(2.12.0.0)包版本:302030000
Apple Developer Tools Xcode 5.0(3332.25)Build 5A1413
Xamarin.iOS版本:7.0.2.7(独立版)哈希:57edee2分支:建立日期:2013-04-10 18:05:51-0400
这是 Xamarin.iOS 代码,但我认为本地人也能发现问题,所以我也将其标记为 ObjC。
我对 UIView 进行子类化并“滥用”它来从视图的 X、Y 到视图的右下边界绘制一条虚线。
我设置的颜色是白色。线条样式应该是虚线。但是我得到一条黑色实线。我在这里做错了什么?
public override void Draw (RectangleF rect)
{
using (CGContext g = UIGraphics.GetCurrentContext ())
{
g.SetLineWidth (1f);
g.SetLineDash (0, new float[] { 10f, 4f });
g.MoveTo (rect.X, rect.Y);
g.AddLineToPoint (rect.Right, rect.Bottom);
g.SetStrokeColor (this.color.CGColor);
g.StrokePath ();
}
}
Run Code Online (Sandbox Code Playgroud) 我的最终目标是使用 bash 和 Azure CLI 将文档上传到现有的 CosmosDB (SQL) 实例。问题是:Azure CLI 不提供修改文档的命令。
为了解决这个问题,我查看了az rest命令,希望调用 CosmosDB 的 REST API 来完成任务,但经过几个小时的不成功尝试后,我总是收到错误:
Unauthorized({"code":"Unauthorized","message":"输入的授权令牌无法满足请求。请检查预期的有效负载是否按照协议构建,并检查正在使用的密钥。服务器使用了以下有效负载进行签名:'get\ndbs\n\nsat,2020 年 4 月 25 日 13:50:22 +0000\n\n'\r\nActivityId: ..., Microsoft.Azure.Documents.Common/2.10.0" })
为了暂时简单起见,我尝试使用 REST API 列出我的所有数据库,如文档中所述,如果可行,请继续实际的文档上传。
我还尝试按照文档中提供的有关如何生成授权标头的说明进行操作。
获取数据库列表的请求使用以下格式:GET https://{databaseaccount}.documents.azure.com/dbs
这是我的 bash 脚本,其中突出显示了问题。
第 1 部分:获取访问令牌 -问题:这是正确的令牌吗?
masterKey=$(az cosmosdb keys list --name MYDBINSTANCENAME --query primaryMasterKey --output tsv)
Run Code Online (Sandbox Code Playgroud)
第 2 部分:生成要哈希的有效负载 - 所有内容必须为小写
verb="get"
resourceType="dbs"
resourceLink="dbs"
now=$((date -uR) | tr '[A-Z]' '[a-z]')
payload="$verb\n$resourceType\n$resourceLink\n$now\n\\n"
Run Code Online (Sandbox Code Playgroud)
第 …
我想知道C#中扩展方法的行为.请参阅以下示例:
static string ExtendedToString( this object oObj )
{
return "Object";
}
static string ExtendedToString( this Array oArray )
{
return "Array";
}
// Example 1: int array - working as expected.
int[] o = new int[] { 1, 2, 3 };
o.ExtendedToString( ); // returns "Array"
// Example 2: array as object - did not expect the result.
object o = new int[] { 1, 2, 3 };
o.ExtendedToString( ); // returns "Object"
Run Code Online (Sandbox Code Playgroud)
为什么(在最后一种情况下)调用了对象的扩展方法而不是int []的方法?
我刚刚开始了一个新的MonoTouch项目.我把它作为一个环球项目开始.
我想以4.0及更高的目标为目标.
当我转到iPhone Build设置并尝试更改SDK版本时,唯一的选项是Default和5.0.
有没有办法定位4.0及更高?我有一个较旧的项目,我升级,它仍然显示所有其他选项.
我有一个List<GKComponentSystem<GKComponent>>和一个通用的Add<T>()方法,约束为Ta GKComponent.
为什么我不能GKComponentSystem<T>在列表中添加实例?请参阅下面的代码:
List<GKComponentSystem<GKComponent>> _systems = new List<GKComponentSystem<GKComponent>>();
public void AddSystem<T>(int position = -1) where T : GKComponent
{
var system = new GKComponentSystem<T>();
_systems.Add(system);
}
Run Code Online (Sandbox Code Playgroud)
错误:
参数#1无法将GameplayKit.GKComponentSystem <T>表达式转换为类型GameplayKit.GKComponentSystem <GameplayKit.GKComponent>
这就行了_systems.Add(system).
我以为我认识C#,但这是我很高兴拥有StackOverflow的情况之一 - 我到底不明白这是什么?
system是一个GKComponentSystem<T>,T必须是一个GKComponent,所以system是一个GKComponentSystem<GKComponent>,我应该能够将它添加到我的列表中.
这是GKComponentSystem:
public class GKComponentSystem<T> : NSObject where T : GKComponent
它T也是GKComponent......
这是关于逆变(我必须要了解更多的主题)?
请参阅下面的代码/ HTML剪辑.我有一个带有"href"的锚点,它位于带有"onclick"事件处理程序的DIV中.如果我单击锚点,浏览器将打开一个新选项卡并执行"onclick".如果用户点击了锚点,我想要执行"onclick".在锚的onclick中返回"false"会破坏href被触发.这里有什么解决方案?
<html>
<head>
<script>
function clicky()
{
alert("Click!");
}
</script>
</head>
<body>
<div id="adiv" onclick="clicky()" style="border:1px solid black;background-color:red;width:400px;height:300px;">
<a href="http://www.gohere.but.dont.execute.onclick.com" target="_blank">a link</a>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
勒内
我现在放弃了这个我一直试图运行的非常简单的测试.我想在我的窗口中添加一个子视图,除了从iPhone的屏幕的一个角落到另一个角落之外什么都没做,然后使用touchesMoved()它应该从最后一个点到当前点画一条线.问题:1.初始线已经不可见了.2.使用Interface Builder时,初始行是可见的,但即使我调用SetNeedsDisplay(),也不会调用drawRect().
这可能不是那么难......有人可以修改下面的代码使它工作吗?
在FinishedLaunching()的main.cs中:
oView = new TestView();
oView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
oView.Frame = new System.Drawing.RectangleF(0, 0, 320, 480);
window.AddSubview(oView);
window.MakeKeyAndVisible ();
Run Code Online (Sandbox Code Playgroud)
TestView.cs:
using System;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using System.Drawing;
using MonoTouch.CoreAnimation;
using MonoTouch.Foundation;
namespace Test
{
public class TestView : UIView
{
public TestView () : base()
{
}
public override void DrawRect (RectangleF area, UIViewPrintFormatter formatter)
{
CGContext oContext = UIGraphics.GetCurrentContext();
oContext.SetStrokeColor(UIColor.Red.CGColor.Components);
oContext.SetLineWidth(3.0f);
this.oLastPoint.Y = UIScreen.MainScreen.ApplicationFrame.Size.Height - this.oLastPoint.Y;
this.oCurrentPoint.Y = UIScreen.MainScreen.ApplicationFrame.Size.Height - this.oCurrentPoint.Y;
oContext.StrokeLineSegments(new PointF[] {this.oLastPoint, …Run Code Online (Sandbox Code Playgroud) 我正在使用带有静态内容的故事板和表格视图.在内部,似乎UITableViewController隐含地成为了它的来源UITableView.
如果我现在想要对静态内容产生影响,我将不得不重写表源的方法.在ObjectiveC我可以放置
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0)
return @"HELLO!";
else {
return [super tableView:tableView titleForHeaderInSection:section];
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,该方法将被覆盖.但在MonoTouch中,这不起作用.请注意,我不想创建委托或数据源的新实例.对于静态单元,控制器是源/委托.在ObjectiveC中,这是通过使控制器实现相应的协议来完成的.
以下是我提出的与此主题相关的问题,但现在我无法将解决方案转换为MonoTouch:
如何附加到当前在iOS模拟器6中运行的应用程序,或者使用Xcode Instruments中的Automation启动应用程序?我正在使用Xcode 4.5.我看到我的应用程序正在模拟器中运行.如果我启动Instruments,我选择"iOS模拟器 - >自动化"模板.然而,顶部的下拉告诉我在"附加到进程"下"当前工具不允许附加",并且在使用"选择目标"时,我从应用程序文件夹中显示了一个应用程序列表,但它们都不是iOS模拟器,因为它在Xcode.app包中.它在设备上运行得很好.
有任何想法吗?
xamarin.ios ×8
c# ×4
cocoa-touch ×2
ios ×2
version ×2
.net ×1
automation ×1
azure ×1
azure-cli ×1
bash ×1
core-data ×1
generics ×1
html ×1
instruments ×1
javascript ×1
monodevelop ×1
objective-c ×1
sdk ×1
uikit ×1
xamarin ×1
xcode ×1